Monday, November 28, 2022

laravel Route Methods

Laravel 7.2 routing with route group auth guard check with prefix

laravel Route Methods


Hello to all, welcome to In this post, I will tell you, laravel Route Methods. 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. Here are the some important laravel Route Methods, with them we can do more with laravel. you can write these methods into routes/web.php file:

1. Simple Method To return view to particular url:

Route::get(‘map’, function(){
return view(‘map’);

 2:Sending emails with Mailgun and Laravel is easy!

Route::get(‘/send-test-email’, function(){
Mail::raw(‘Sending emails with Mailgun and Laravel is easy!’, function($message)
$message->subject(‘Mailgun and Laravel are awesome!’);
// $message->from(‘’, ‘Website Name’);

Mail::to(‘’)->send(new App\Mail\CustomerWelcomeMessage());

 3:Sending simple emails with Laravel is easy!

Route::get(‘/added-new-product-mail’, function(){
Mail::to(‘’)->send(new App\Mail\AddNewProduct($product));
return view(’emails.admin.addednewproduct’);

 4:redirection in laravel routes!

Route::get(‘/test-page’, function () {
return Redirect::to(‘/blog/test-page’, 301); 

 5. Custom Routes:

Route::view('/', 'home'); // Home page
Route::view('/about', 'about'); // About Page
Route::view('/contact', 'contact'); // Contact Page

 6. Routing with parameters:

Route::get('user/{id}', function ($id) {
  return 'User '.$id;

 7. Routing with regular expressions:

Route::get('user/{name}', function ($name) {
})->where('name', '[A-Za-z]+'); // only alphabets accepted for name parameter
Route::get('user/{id}', function ($id) {
})->where('id', '[0-9]+'); // only digits accepted for id parameter
Route::get('user/{id}/{name}', function ($id, $name) {
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']); // multiple parameter with required expressions

 8. Auth check routing:

    'prefix' => 'admin',
      'middleware => [
  ], function() {
  Route::get('/admindashboard', 'AdminController@admindashboard');

 9. Match Method Routing:

Route::match([methods], $uri, $callback);
Route::any('bar', function () {

 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.

the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Angular 13, Angular 14, Angular 15, 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.