你好,我在这里说一个错误:
Symfony \组件\ HttpKernel \ Exception \ MethodNotAllowedHttpException 没有消息
当我更新内容时。我有一张图片和一张视图要更新。
下面是我的观点。内容在哪里编码。我这里有“提交”按钮,它将触发更新。和格式@update
。
admin / airlineplus / paxsafety.blade.php
{!! Form::open(['action'=>['Admin\PaxSafetyController@update', $paxsafe->id], 'method' => 'POST','enctype'=>'multipart/form-data']) !!}
<div class="form-group">
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th>Upload new Image and Video</th>
<td> {{ Form::file('paxsafety_image[]') }} <strong>{{ $paxsafe->paxsafety_image }} </strong> </td>
<td> {{ Form::file('paxsafety_video[]') }} <strong>{{ $paxsafe->paxsafety_video }} </strong></td>
</td>
</tr>
</table><br><br>
{{Form::submit('submit', ['class'=>'btn btn-primary', 'name'=>'submit'])}}
</div>
</div>
{!! Form::close() !!}
接下来,我的控制器。
MyCoolController.php
$this->validate($request, [
'paxsafety_image' => 'required',
'paxsafety_video' => 'required'
]);
if ($request->has('paxsafety_image') && $request->has('paxsafety_video'))
{
//Handle File Upload
$paxSafety = [];
foreach ($request->file('paxsafety_image') as $key => $file)
{
// Get FileName
$filenameWithExt = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt, PATHINFO_FILENAME);
//Get just extension
$extension = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload Image
$path = $file->storeAs('public/paxsafety_folder',$fileNameToStore);
array_push($paxSafety, $fileNameToStore);
}
$paxSafetyVideo = [];
foreach ($request->file('paxsafety_video') as $key => $file)
{
// Get FileName
$filenameWithExt2 = $file->getClientOriginalName();
//Get just filename
$filename = pathinfo( $filenameWithExt2, PATHINFO_FILENAME);
//Get just extension
$extension2 = $file->getClientOriginalExtension();
//Filename to Store
$fileNameToStore2 = $filename.'_'.time().'.'.$extension2;
//Upload Image
$path = $file->storeAs('public/paxsafety_folder',$fileNameToStore2);
array_push($paxSafetyVideo, $fileNameToStore2);
}
$fileNameToStore = serialize($paxSafety);
$fileNameToStore2 = serialize($paxSafetyVideo);
}
foreach ($paxSafety as $key => $value) {
foreach ($paxSafetyVideo as $key => $values) {
$paxsafe = PaxSafety::find($id);
if($request->hasFile('paxsafety_image')){
$paxsafe->paxsafety_image = $value;
}
if($request->hasFile('paxsafety_video')){
$paxsafe->paxsafety_video = $values;
}
$paxsafe->save();
}
}
return redirect('/admin/airlineplus/paxsafety')->with('success', 'Inflight Magazine Content Inserted');
指导我,请问我是Laravel编码的新手
答案 0 :(得分:2)
侦听您的函数的动词是 PUT ,在您的代码中,您使用动词 POST 解决你的问题 {{Form :: hidden('_ method','PUT')}} 以您的形式