Laravel Valet with SubDomain

In order to allow to use Laravel Sub Domain Route in Your Laravel Valet.

Let’s say my project folder name is ‘forum’. I would like the forum users to have their own public profile page via sub-domain.

Here is my route file:-

Route::domain('{account}.forum.dev')->group(function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});

In my Valet Folder. I need to use a symlink to archive the goal. In my case, I use Ken as a test user. Unfortunately, you can’t archive it via wildcard in Valet.

ln -s forum ken.forum

That’s all. Happy Coding

Laravel Valet with localtunnel.me

There is a very power command with Laravel Valet which is valet share. However, the problem is the URL will not reserve. Once you restart the process, there will be new URL will be generated.

When I due with payment gateway, they required an URL can be accessed from outside. So localtunnel.me is the solution to keep the sub-domain.

Once you install localtunnel.me, here is the command:-

>lt --port 80 --subdomain mysubdomain --local-host foldername.dev

It will proxy the valet URL to match with the localtunnel URL.

However, you will still have another issue, all your website link is not showing mysubdomain.localtunnel.me, it is still pointing to foldername.dev.

In this case you can use Laravel URL class, URL::forceRootUrl('http://mysubdomain.localtunnel.me/');

It will change the URL to the input that you had set.

I hope this tutorial can help you in your development. Happy Coding~