dongsuyou6938 2016-03-13 03:22
浏览 95
已采纳

Laravel错误:RouteCollection.php第219行中的MethodNotAllowedHttpException

When i want to insert data in the database i get this error

MethodNotAllowedHttpException in RouteCollection.php line 219

I'm use resource controller

this is my form

<form action="library" method="POST" enctype="multipart/form-data">
    {!! csrf_field() !!}
        Enter the name of section: <input type="text" name="section_name"> <br>
        Upload an image: <input type="file" name="image"> <br>
        <button type="submit" class="btn btn-default">Create Section</button>
    </form>

and this is my store function

public function store(Request $request)
{

    $section_name = $request->input('section_name');
    $file = $request->file('image');
    $destenationPath = 'iamges';
    $filename = $file->getClientOriginalName();
    $file->move($destenationPath, $filename);
    DB::table('sections')->insert(['section_name' => $section_name, 'image_name' => $filename]);
    return redirect('admin');

}

and this my Route

Route::resource('library', 'Main');
  • 写回答

3条回答 默认 最新

  • doudi2833 2016-03-13 06:42
    关注

    You are using action="library", so the form is submitted to library. But, here is nothing to deal with library. You need to submit the form to store() method in Mian controller.

    Change action="library" to action="{{ action('Main@store') }}" in form starting tag.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部