简体   繁体   English

RouteCollection.php 第 219 行中的 Laravel 5 MethodNotAllowedHttpException

[英]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');
  1. 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 提供程序。

  2. 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.

相关问题 Laravel 5:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5: MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 5在RouteCollection.php第219行中的MethodNotAllowedHttpException: - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219: Laravel API 中 RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php line 219 in laravel API's Laravel 5.2:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - Laravel 5.2 : MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 错误:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - Laravel error: MethodNotAllowedHttpException in RouteCollection.php line 219 在Laravel中在RouteCollection.php第219行中获取MethodNotAllowedHttpException - Getting MethodNotAllowedHttpException in RouteCollection.php line 219: on laravel 在RouteCollection.php第219行中的Laravel 5.2 MethodNotAllowedHttpException - Laravel 5.2 MethodNotAllowedHttpException in RouteCollection.php line 219 RouteCollection.php 219行中的MethodNotAllowedHttpException错误laravel: - MethodNotAllowedHttpException in RouteCollection.php line 219 error laravel: Laravel 5.1.26:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5.1.26 : MethodNotAllowedHttpException in RouteCollection.php line 219 RouteCollection.php第219行中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php line 219
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM