In Laravel, routes are used to map URLs to specific controller actions. There are several ways to define routes in a Laravel application, but the most common method is to use the Route
facade in the routes file located at routes/web.php
.
Here is an example of how to define a route in Laravel using the Route
facade:
use Illuminate\Support\Facades\Route;
Route::get('/users', 'UserController@index');
This route will map the URL /users
to the index
method of the UserController
controller. When a user visits the /users
URL, the index
method of the UserController
will be executed.
You can also define routes for other HTTP methods, such as POST
, PUT
, and DELETE
, using the corresponding method on the Route
facade. For example:
Route::post('/users', 'UserController@store');
Route::put('/users/{id}', 'UserController@update');
Route::delete('/users/{id}', 'UserController@destroy');