简体   繁体   中英

Laravel 5.1 resource route does not work properly

// routes.php
Route::resource('/image', 'ImageController');
Route::get('/create', 'ImageController@create');
Route::post('/store', 'ImageController@store');

// create.blade.php
{!! Form::open(array('url' => '/store', 'method'=>'POST')) !!}
    .......
{!! Form::close() !!}

Here if i don't write these two lines (Route::get('/create', 'ImageController@create'); Route::post('/store', 'ImageController@store');) The resource routing of create and store does not work and show some errors. Why this happens? Thanks in advance.

When creating resource route you don't have to create individual routes. Because all RESTfull default routes will be created for you automatically.

You just need following route

Route::resource('image', 'ImageController');

then change form as below

{!! Form::open(array('route' => array('image.store'))) !!}
    .......
{!! Form::close() !!}

Read More

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM