Risan Bagja

Windows, PHP 8, Laravel Subdomain Routing

Install PHP 8 on Windows

Today I managed to install the latest PHP version 8 on my Windows machine. It’s a pretty straightforward process:

Host File Location on Windows

On Windows 10, the host file is located at:

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

The format is the same as the one found on Linux or macOS. So unfortunately you cannot set a wildcard subdomain entry too.

102.54.94.97   foo.example.com      # Some comment
127.0.0.1      project.test 
127.0.0.1      secret.project.test

Laravel Subdomain Routing

I know that Laravel has support for subdomain routing for a long time. It goes as early as version 4 in 2013—the first version of Laravel that I used. But I never really tried that feature, until today. It just works out-of-the-box. Of course, you still need to properly configure your webserver to point those subdomains to your Laravel’s public directory. But it still blew my mind.

Route::domain('{user}.example.com')->group(function () {
    Route::get('/messages/{id}', function ($user, $id) {
        // Get the {user} value through $user
    });
});