Laravel-MongoDB CRUD

Create Routes

Now we have to provide the routes to map URLs with Controller Actions. You may either add the routes manually or register a resourceful route to the controller. The routes have to be defined in strong>routes/web.php

In this example we are registering a resourceful route to the controller.

Route::resource('books', 'BookController');

You may check the routes from artisan CLI.


php artisan route:list


+--------+-----------+-------------------+---------------+---------------------------------------------+--------------+
| Domain | Method    | URI               | Name          | Action                                      | Middleware   |
+--------+-----------+-------------------+---------------+---------------------------------------------+--------------+
|        | GET|HEAD  | api/user          |               | Closure                                     | api,auth:api |
|        | POST      | books             | books.store   | App\Http\Controllers\BookController@store   | web          |
|        | GET|HEAD  | books             | books.index   | App\Http\Controllers\BookController@index   | web          |
|        | GET|HEAD  | books/create      | books.create  | App\Http\Controllers\BookController@create  | web          |
|        | DELETE    | books/{book}      | books.destroy | App\Http\Controllers\BookController@destroy | web          |
|        | PUT|PATCH | books/{book}      | books.update  | App\Http\Controllers\BookController@update  | web          |
|        | GET|HEAD  | books/{book}      | books.show    | App\Http\Controllers\BookController@show    | web          |
|        | GET|HEAD  | books/{book}/edit | books.edit    | App\Http\Controllers\BookController@edit    | web          |
+--------+-----------+-------------------+---------------+---------------------------------------------+--------------+

Note that the books.store route corresponds to a POST method, whereas books.update is done by PUT method. Also books.destroy corresponds to DELETE method.

Last Updated: 10-October-2016


Post a comment

Name

Your Comment

Email (We dont publish it)

Comments

Nothing yet..be the first to share wisdom.