Categories

Saturday, December 21, 2024
#919814419350 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

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

therichpost
the authortherichpost
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 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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