Laravel
340
w3alert.com
04-01-2020
In laravel, all HTTP or https requests are allowed with the help of routes. Because laravel routing allows to associated all requests from controllers. In this laravel routing tutorial, you will learn about the routing in Laravel.
Basic routing in laravel, all requests are allowed with the help of routes. You can go to the application routes folder and define routes here. For your web application you can define application related routes in routes/web.php file and routes/api.php, here define api related routes
routes/web.php, Here is the basic routing example for demonstration:
Route::get('/', function () { return view('welcome'); });
Routing with Controller Functions in laravel, all requests are allowed with the help of routes. You can pass a controller method into the route. When you request from the browser or hit the route on browser. This method of the defined controller will be perform the it's action.
routes/web.php, Here is the routing with controller example for demonstration:
Route::get('/privacy-policy', '[email protected]');
Laravel framework allow to pass parameters in routes. So You can easily pass the parameters in routes.
routes/web.php, Here is the routing with parameters example for demonstration:
Route::get('/page/{num}', function ($num) { echo "Your are on page ". $num; });
Laravel framework has very special and most important features of naming in routes. It allows to the routes to creating URLs to redirect. In other words, we can say that the naming route is the way of providing a nickname to the route in laravel web application.
routes/web.php, Here is the basic naming routes example for demonstration:
Route::post('/submit', '[email protected]')->name('contact.submit');
In laravel group routing allow to group specific or each routes with prefix, middlewares, properties etc.
routes/web.php, Here is the Laravel Group Route example for demonstration:
Route::group(['prefix' => 'admin', 'as' => 'admin.'], function () { Route::get('/', '[email protected]')->name('index'); Route::get('/login', '[email protected]')->name('index'); Route::post('/login' '[email protected]')->name('postLogin'); });
Laravel routes groups also allow using namespace with routes.
routes/web.php, Here is the Laravel Namespaces in Laravel Route Groups example for demonstration:
Route::group(['namespace' => 'Admin'])