我已经编写了一些代码,用于使用crud表将徽标(图片)上传到广播电台,上传功能在创建新广播电台时有效,现在我使用以下内容为同一个crud表创建了更新功能控制器中的代码:
public function update(Request $request, $id)
{
request()->validate([
'title' => 'required',
'url' => 'required',
'logo' => 'nullable',
]);
if ($request['logo'] === null) {
Internetradiostations::find($id)->update($request->all());
return redirect()->route('internetradiostationseditor.index')
->with('success','Internet radio station ge-updated');
} else {
$input['logo'] = time().'.'.$request->logo->getClientOriginalExtension();
$request->logo->move(public_path('logos'), $input['logo']);
$input['title'] = $request->title;
$input['url'] = $request->url;
Internetradiostations::find($id)->update($input);
return redirect()->route('internetradiostationseditor.index')
->with('success','Internet radio station ge-updated');
}
}
执行代码时出现以下错误:
Call to a member function getClientOriginalExtension() on string
任何人都知道如何解决这个问题?我只更改了create to update:
Internetradiostations::create($input);
要:
Internetradiostations::find($id)->update($input);
答案 0 :(得分:1)
@Dmitry谢谢!,你是对的,通过更改刀片internetradiostationseditor.edit的表单开头解决了:
自:
{!! Form::model($internetradiostation, ['method' => 'PATCH','route' => ['internetradiostationseditor.update', $internetradiostation->id]]) !!}
要:
{!! Form::model($internetradiostation, ['method' => 'PATCH','route' => ['internetradiostationseditor.update', $internetradiostation->id], 'files'=>true, 'enctype'=>'multipart/form-data']) !!}