Configuration

Table des matières

1. Internationalization

Languages can be retrieved from https://github.com/caouecs/Laravel-lang.

Languages should be copied into the folder /resources/lang.

2. Files

2.1. env

2.1.1. Database

The .env file in the root folder will contains configurations items like the datababase’s credentials.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

2.1.2. email

MAIL_DRIVER=smtp
MAIL_HOST=smtp.xxxxx.com
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

2.1.3. Debugging

The .env file contains a constant called APP_DEBUG. By setting that variable to true, additional errors messages will be displayed.

By putting the application to the production environment, don’t forget to set APP_DEBUG to false.

2.2. htaccess

The .htaccess file of Laravel is located under /public/.htaccess and contains, by default:

<IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
      Options -MultiViews -Indexes
   </IfModule>

   RewriteEngine On

   # Handle Authorization Header
   RewriteCond %{HTTP:Authorization} .
   RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

   # Redirect Trailing Slashes If Not A Folder...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_URI} (.+)/$
   RewriteRule ^ %1 [L,R=301]

   # Handle Front Controller...
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^ index.php [L]
</IfModule>

3. Folders

3.1. public

The only one folder that needs to be accessible to the user through the web. That means that, without exceptions, all the rest (folders app, bootstrap, config, database, ...) shouldn’t be accessible from the web.

The public folder is also the only one with a 755 chmod.

4. Paths

4.1. Override

It’s possible to overwrite default paths like, f.i., the paths for the views.

By default, it’s /resources/views but we can change it by using the method Config::set()

Config::set('view.paths', [base_path().'/my_own_view_path']);

4.2. Set our own

We can create our one paths like one for images, documentations, ...

To respect the Laravel’s framework, we just need to add a file in the /config folder, f.i. adding /config/images.php.

<?php
return ['path' => 'uploads'];

The content is really straightforward: the return is an associative array (key->value).

When added, we can immediately use it:

echo config('images.path');