oli18
12/30/2017 - 1:47 PM

Laravel CRUD routing convention

Basic blueprint of a resourceful routing in Laravel 5.5

<?php

// If we can represent a resource as for example, posts then the routing convention for its crud operations are as follows :



Route::get('/posts', 'PostsController@index'); //it will show all the posts using iteration

Route::get('/posts/create', 'PostsController@create');  //it will show a form to post to database

Route::post('/posts', 'PostsController@store'); //this will call a put request to posts route to store the form to DB

Route::get('/posts/{id}/edit', 'PostsController@edit') //this will show a form to edit/update a post

Route::patch('/posts/{id}', '@PostsController@update') //this will submit a PUT/PATCH request for updating a post

Route::get('/posts/{id}', 'PostsController@show') //To show a particular post

Route::delete('/posts/{id}', 'PostsController@destroy') //to Delete a specific post by spoofing a delete request from view


//To generate a resourceful controller with prefilled crud functions :
//php artisan make:controller PostsController -r