我正在使用我的控制器验证和存储图像。
当我验证图像表格没有存储在数据库中但是当我评论验证它存储在数据库中时。
FrontController.php
public function StorePost(Request $request)
{
$formInput = $request->except('image');
$this->validate($request, [
'title' => 'required',
'name' => 'required',
'email' => 'required|email',
'contact' => 'required',
'model' => 'required',
'city' => 'required',
'description' => 'required',
'image' => 'image|mimes:png,jpg,jpeg|max:10000'
]);
//image upload
$image = $request->image;
if($image){
$imageName = $image->getClientOriginalName();
$image->move('images', $imageName);
$formInput['image'] = $imageName;
}
Post::create($formInput);
$posts = Post::all();
return view('ad.ad', compact('name', 'posts'));
}