【发布时间】:2016-08-30 10:02:13
【问题描述】:
我正在尝试在 Laravel 5 中制作图像上传器,但我仍然收到此错误:
RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException
什么会导致这个问题?
表格:
<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">
路由.php
Route::post('uploadImage', [
'as' => 'uploadImage',
'uses' => 'HomeController@uploadImage'
]);
HomeController.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('/');
}
谢谢。
【问题讨论】:
-
旁注,在 Laravel 5 中只使用
route('uploadImage')而不是URL::route('uploadImage')。由于URL工厂已被弃用。 -
您从哪里听说
UrlGenerator已被弃用?URL只是一个门面,不要认为它会被弃用...... -
我不是导致此错误的原因,我更改了它,但还是一样。
-
在这个之前的routes.php文件中是否声明了任何路由?
标签: php laravel exception laravel-5 routing