报错
参数太少,无法发挥作用AppHttpControllersAdminController::updateSlider(), 1在E:localhostJMSvendorlaravelframeworksrcIlluminateRoutingController.php第54行传递,正好2期望
控制器
public function updateSlider(Request $request,$id)
{
$this->validate(request(),[
//put fields to be validated here
]);
$oldImage=DB::table('slider')->where('id',$id)->first();
$oldFile=$oldImage->image;
$task=array();
$current_date_time = date('Y-m-d H:i:s');
$task['updated_at']=$current_date_time;
$file=$request->file('image');
$file_name=hexdec(uniqid());
$ext=strtolower($file->getClientOriginalExtension());
$file_full_name=$file_name.'.'.$ext;
$upload_path='Gallery/';
$file_url=$upload_path.$file_full_name;
$success=$file->move($upload_path,$file_full_name);
$task['photo']=$file_url;
$data=DB::table('slider')->update($task);
if ($data) {
unlink($oldFile);
return back()->with('success', 'Photo Has Been Saved Successfully.');
}
}
格式为
<form action="{{ url('admin/slider/update/.$data->id') }}" method="POST"enctype="multipart/form-data">
@csrf
<input type="file" name="image" class="custom-file-input" >
<button type="submit"class="btn btn-primary">Update </i></button>
</form>
而不是:
<form action="{{ url('admin/slider/update/.$data->id') }}" blabla>
试试这个:
<form action="/admin/slider/update/{{ $data->id }}" blabla>