[英]Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219
I am trying to make image uploader in Laravel 5, but I am strill getting this error:我正在尝试在 Laravel 5 中制作图片上传器,但我仍然收到此错误:
MethodNotAllowedHttpException in RouteCollection.php line 219 RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException
What can cause this problem?什么会导致这个问题?
Form:形式:
<form name="upload_image" method="post" action="{{URL::route('uploadImage')}}">
<input type="file" accept="image/*">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" name="submit">
routes.php路由文件
Route::post('uploadImage', [
'as' => 'uploadImage',
'uses' => 'HomeController@uploadImage'
]);
HomeController.php家庭控制器.php
public function uploadImage() {
if (Auth::check()) {
if (Auth::user()->admin == 1) {
$image = Input::get('image');
$filename = time() . '.' . $image->getClientOriginalExtension();
$path = public_path('articleImages/' . $filename);
Image::make($image->getRealPath())->resize(600, 400)->save($path);
return view('admin.uploadImage')->with('path', $path);
}
return view('/');
}
return view('/');
}
Thank you.谢谢你。
更改 URL::route
<form name="upload_image" method="post" action="{{route('uploadImage')}}">
first of all you need names for input elements like this :首先,您需要输入元素的名称,如下所示:
<form name="upload_image" method="post" action="{{URL::route('uploadImage')}}">
<input name="image" type="file" accept="image/*">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" name="submit">
2nd thing that you can write the routes like this :第二件事,你可以写这样的路线:
Route::post('uploadImage','HomeController@uploadImage');
With Laravel 5 you have to use {{ route('uploadImage') }}
instead of {{URL::route('uploadImage')}}
because Laravel no longer uses URL provider.对于 Laravel 5,您必须使用{{ route('uploadImage') }}
而不是{{URL::route('uploadImage')}}
因为 Laravel 不再使用 URL 提供程序。
Have you forgot to put enctype="multipart/form-data"
in your form?您是否忘记在enctype="multipart/form-data"
放置enctype="multipart/form-data"
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.