route laravel code example
Example 1: laravel get route
Route::get('foo', function () {
return 'Hello World';
});
Example 2: route resource laravel
Verb Path Action Route Name
GET /users index users.index
GET /users/create create users.create
POST /users store users.store
GET /users/{user} show users.show
GET /users/{user}/edit edit users.edit
PUT|PATCH /users/{user} update users.update
DELETE /users/{user} destroy users.destroy
Example 3: named route with parameter laravel
Route::get('/menu/{category}/{product}/{item}', ['as' => 'named.route' , 'uses' => 'MenuController@listItem']);
route('named.route', ['category' => $category->id, 'product' => $product->id, 'item' => $item->id]);
Example 4: laravel route namespace and prefix
Route::prefix('admin')->group(function () {
Route::get('/users', function () {
});
});
Example 5: laravel get route
Route::get('/user', 'UserController@index');
Example 6: laravel routes return view in web.php
Route::get("/page", function(){
return View::make("dir.page");
});