Sunday, July 12, 2020
therichposts@gmail.com
LaravelPhp

What is the use of Prefix in Laravel Routes?

Laravel 7.2 routing with route group auth guard check with prefix

Use of Prefix in Laravel Routes

Views

Hello to all, welcome to therichpost.com. In this post, I will tell you, What is the use of Prefix in Laravel Routes? I am doing with laravel first time in my website. Laravel is one of the top php mvc framework.
I personally like laravel routes feature very much.

By my understanding in basic way, laravel prefix works as if we have same route(uri) with multiple queries or fuctions in same controller

routes/web.php file:

Route::group([‘prefix’ => ‘user’], function() {

Route::get(‘/’, ‘UserController@index’);

Route::post(‘/get-business-hours’, ‘UserController@getBusinessHours’)->middleware(‘ajax’);

Route::get(‘/get-all-bookings’, ‘UserController@getAllBookings’)->middleware(‘ajax’);

Route::post(‘/get-product-categories’, ‘UserController@getProductCategories’)->middleware(‘ajax’);

Route::post(‘/get-products’, ‘UserController@getProducts’)->middleware(‘ajax’);

Route::post(‘/checkout’, ‘UserController@handleCheckout’)->middleware(‘ajax’);

});

In controller file app/Http/Controllers/UserController.php:

public function getBusinessHours(Request $request)
{}
public function getAllBookings(Request $request)
{}
public function getProductCategories(Request $req)
{}
public function getProducts(Request $req)
{}
public function handleCheckout(Request $req)
{}

There are so many code tricks in laravel and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.