{!! Form::open(['route' => 'product.store', 'method' => 'post', 'files' => true]) !!}
{!! Form::close() !!}
我使用此代码但会产生以下错误
FatalThrowableError
在字符串上调用成员函数getClientOriginalName()
public function store(Request $request)
{
$formInput = $request->except('image');
$image = $request->image;
if($image){
$imageName = $image->getClientOriginalName();
$image->move('images',$imageName);
$formInput['image'] = $imageName;
}
Product::create($formInput);
return redirect()->route('admin.index');
}
答案 0 :(得分:0)
如果要获取文件扩展名,请使用file()
public function store(Request $request)
{
$formInput = $request->except('image');
if($image){
$ext = $request->file('image')->getClientOriginalExtension();
$image->move('images',$imageName);
$formInput['image'] = $imageName;
}
Product::create($formInput);
return redirect()->route('admin.index');
}