// Implicit Model Binding Routes can be created with one line using either:
Route::resource('photos', PhotoController::class);
// OR
Route::resources([
'photos' => PhotoController::class,
'posts' => PostController::class,
]);
php artisan make:controller PhotoController --resource --model=Photo
// makes a controller with stubouts for methods:
// index
// create
// store
// show
// edit
// update
// destroy
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
By default, all resource controller actions have a route name;
however, you can override these names by passing a names array
with your desired route names:
use AppHttpControllersPhotoController;
Route::resource('photos', PhotoController::class)->names([
'create' => 'photos.build'
]);
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class BlogController extends Controller
{
/**
* Display a listing of the resource.
*
* @return IlluminateHttpResponse
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return IlluminateHttpResponse
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param IlluminateHttpRequest $request
* @return IlluminateHttpResponse
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param IlluminateHttpRequest $request
* @param int $id
* @return IlluminateHttpResponse
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return IlluminateHttpResponse
*/
public function destroy($id)
{
//
}
}
By default, Route::resource will create the route parameters
for your resource routes based on the "singularized" version
of the resource name. You can easily override this on a per resource
basis using the parameters method. The array passed into the parameters
method should be an associative array of resource names and parameter names:
use AppHttpControllersAdminUserController;
Route::resource('users', AdminUserController::class)->parameters([
'users' => 'admin_user'
]);
<?php
use IlluminateSupportFacadesRoute;
use AppHttpControllersProductController;
Route::get('/', function () {
return view('welcome');
});
Route::resource('product',ProductController::class);