Laravel Framework | PHP & MySQL | Tutorials

David Carr

Laravel 5.5 use a prefix on database tables

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

DB_PREFIX=laravel_

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

Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.