03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Multisites 202<br />

Note on Running Commands in Local Environment<br />

The moment you add multiple environments to your application, you create the possibility that<br />

artisan commands might be run on the incorrect environment.<br />

Just because Laravel 4 is capable of executing in the correct environment doesn’t mean you will<br />

always remember which environment you are in or which environment you should be in…<br />

Start learning to provide the environment for every artisan command, when you’re working with<br />

multiple environments. It’s a good habit to get into.<br />

Using Site-Specific Views<br />

One of the benefits of multiple environment-specific configuration sets is that we can load different<br />

views for different sites. Let’s begin by creating a few:<br />

1 127.0.0.1 dev.www.tutorial-laravel-4-multisites<br />

2 127.0.0.1 dev.admin.tutorial-laravel-4-multisites<br />

.<br />

This was extracted from /etc/hosts.<br />

You can really create any domains you want, but for this part we’re going to need multiple domains<br />

pointing to our testing server so that we can actually see different view files being loaded, based on<br />

domain.<br />

Next, update your app/bootstrap/start.php file to include the virtual host domains you’ve created:<br />

1 $env = $app->detectEnvironment([<br />

2 "www" => ["dev.www.tutorial-laravel-4-multisites"],<br />

3 "admin" => ["dev.admin.tutorial-laravel-4-multisites"]<br />

4 ]);<br />

.<br />

This was extracted from /bootstrap/start.php.<br />

.<br />

Phil Sturgeon made an excellent point about not using URL’s to toggle environments, as somebody<br />

can easily set a hostname to match your development environment and point it to your production<br />

environment to cause unexpected results. This can lead to people gleaning more information than

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!