Raviya Technical
Published in

Raviya Technical

Laravel Basic | Laravel 7/6 Resource Route and Controller Tutorial

Route::get('items',['as'=>'items.index','uses'=>'ItemController@index']);Route::post('items/create',['as'=>'items.store','uses'=>'ItemController@store']);Route::get('items/edit/{id}',['as'=>'items.edit','uses'=>'ItemController@edit']);Route::patch('items/{id}',['as'=>'items.update','uses'=>'ItemController@update']);Route::delete('items/{id}',['as'=>'items.destroy','uses'=>'ItemController@destroy']);Route::get('items/{id}',['as'=>'items.view','uses'=>'ItemController@view']);
Route::resource('items', 'ItemController');
php artisan route:list
+--------+-----------+-------------------+---------------+---------------------------------------------+--------------+| Domain | Method    | URI               | Name          | Action                                      | Middleware   |+--------+-----------+-------------------+---------------+---------------------------------------------+--------------+|        | GET|HEAD  | api/user          |               | Closure                                     | api,auth:api ||        | GET|HEAD  | items             | items.index   | App\Http\Controllers\ItemController@index   | web          ||        | POST      | items             | items.store   | App\Http\Controllers\ItemController@store   | web          ||        | GET|HEAD  | items/create      | items.create  | App\Http\Controllers\ItemController@create  | web          ||        | GET|HEAD  | items/{item}      | items.show    | App\Http\Controllers\ItemController@show    | web          ||        | PUT|PATCH | items/{item}      | items.update  | App\Http\Controllers\ItemController@update  | web          ||        | DELETE    | items/{item}      | items.destroy | App\Http\Controllers\ItemController@destroy | web          ||        | GET|HEAD  | items/{item}/edit | items.edit    | App\Http\Controllers\ItemController@edit    | web          |+--------+-----------+-------------------+---------------+---------------------------------------------+--------------+
php artisan make:controller ItemController --resource --model=Item
<?phpnamespace App\Http\Controllers;use App\Item;use Illuminate\Http\Request;class ItemController extends Controller{/*** Display a listing of the resource.** @return \Illuminate\Http\Response*/public function index(){}/*** Show the form for creating a new resource.** @return \Illuminate\Http\Response*/public function create(){}/*** Store a newly created resource in storage.** @param  \Illuminate\Http\Request  $request* @return \Illuminate\Http\Response*/public function store(Request $request){}/*** Display the specified resource.** @param  \App\Item  $item* @return \Illuminate\Http\Response*/public function show(Item $item){}/*** Show the form for editing the specified resource.** @param  \App\Item  $item* @return \Illuminate\Http\Response*/public function edit(Item $item){}/*** Update the specified resource in storage.** @param  \Illuminate\Http\Request  $request* @param  \App\Item  $item* @return \Illuminate\Http\Response*/public function update(Request $request, Item $item){}/*** Remove the specified resource from storage.** @param  \App\Item  $item* @return \Illuminate\Http\Response*/public function destroy(Item $item){}}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store