Tutorials, PHP & MySQL, Laravel Framework

I like to prefix my database tables to avoid any conflicts if using different applications within the same database ie have a CMS + a shop sharing the same database.

This is easy to do with Laravel in `app/config/database.php` there is 

'prefix' => '',

You can put your prefix there or use the .env file.

I’ll use the .enf file by adding the following:

'prefix' => env('DB_PREFIX', ''),

This will create a key called DB_PREFIX with a default value of none then in my .env file:

Set the prefix


Now all queries will look for tables that start with laravel_ before the table name, no further adjustments are required.