Omer Farooq
Omer Farooq

Reputation: 4064

Laravel - Do something every time Laravel runs

I have a situation where i have different domains having the A record for my server. So all the domains are pointing to the same laravel server. Now when ever laravel runs i want to get the domain name that sent the request and then change the logo of the website. What is most efficient way of doing this?

I want to keep it light and simple. I just have a few domains so i dont have any issues hardcoding them up to save a db query.

Upvotes: 1

Views: 222

Answers (1)

Hayk Aghabekyan
Hayk Aghabekyan

Reputation: 1087

You can write your code in your BaseController.php and pass some value to your view to show right logo.

For getting domain name you can simple use Laravel method

if (strpos(Request::root(), 'domain1.com') !== false) {
    $domain = 1;
} else if (strpos(Request::root(), 'domain2.com') !== false) {
    $domain = 2;
} else {
    $domain = 3;
}

And as I mentioned above, you can share $domain with your view.

Upvotes: 1

Related Questions