错误
Symfony \ Component \ Debug \ Exception \ FatalThrowableError抛出消息"调用成员函数getClientOriginalExtension()on null"
堆栈跟踪:
控制器
public function store(Request $request)
{
$this->validate(request(),[
'title' => 'required',
'image' => 'image|mimes:jpeg,png,jpg,gif,svg',
'body' => 'required',
]);
$imageName = time().'.'.$request->image_file->getClientOriginalExtension();
$request->image->move(public_path('image'), $imageName);
auth()->user()->publish(
new Post(request(['title','body']))
);
session()->flash('message', 'your post has now been published');
return redirect('/');
}
答案 0 :(得分:0)
您似乎应该使用image
,因为您正在验证image
而不是image_file
:
$request->image->getClientOriginalExtension()