How to use subdomains as parameters in your routes (or in your web.php file)

Laravel: How to use subdomains as parameters in your routes (or in your web.php file)

You can use subdomains in your routes. You can either have certain routes for certain subdomains, or pass the subdomain as a parameter in the routing.

  1. Route::domain('{account}.example.com')->group(function () {
  2.     Route::get('user/{id}', function ($account, $id) {
  3.         //
  4.     });
  5. });

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to use subdomains as parameters in your routes (or in your web.php file)

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to add a name prefix to all routes in a group?

How to namespace a Laravel route group?

How to generate an array for a dropdown (with ['key' => 'value']) suitable for a dropdown, from a Laravel collection of Eloquent objects?

How to remove .php from the end of URLs with .htaccess

How to run an artisan command from a controller

How to block access to certain referrers in Apache using .htaccess

What is Agile software development?

How to fix the MySQL related "Specified key was too long error" error in Laravel

How to make multiple routes share the same URL structure or URL parameters

What is the difference between empty(), isset(), != null, is_null() in PHP