Domain Routing

  • Domain routing in Laravel allows you to route requests to different domains or subdomains to specific controllers and actions. This is useful for building applications with multiple subdomains or domain-specific routes.

In web.php

Route::domain(‘example.local’)->group(function () { Route::get(‘/’, [UserController::class, ‘showProfile’]);

// Add more routes for example.com if needed

});

// Route for a subdomain

Route::domain(‘subdomain.example.local’)->group(function () { Route::get(‘/’, [UserController::class, ‘showProfile’]);

// Add more routes for subdomain.example.com if needed

});

In C:\Windows\System32\drivers\etc\hosts

  1. example.local
  2. subdomain.example.local

Clearing DNS Cache

  • In Command Prompt

ipconfig /flushdns

Now access URL in this way

example.local:8000 Subdomain.example.local:8000

 

[pdf_note link=”https://drive.google.com/file/d/19mBRYjEYzo8nqTHbyuDCuPXvY4T1sC1e/view”]