Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cvikcangle's avatar

Rename default Laravel tables

I've been trying to find a way to rename default Laravel tables like:

+------------------------+
| Tables_in_laravel      |
+------------------------+
| cache                  |
| cache_locks            |
| failed_jobs            |
| job_batches            |
| jobs                   |
| migrations             |
| password_reset_tokens  |
| personal_access_tokens |
| sessions               |
| users                  |
+------------------------+

I would like to have all those tables prefixed in order to prevent current and future conflicts with my tables. For example, I have model Job which is part of very complex structure, and now I'm having obvious issues.

Also, who knows what future brings - maybe tables like news, products, categories etc. will be included in default installation as well. It would be great if there's a way to prefix all system tables and to prevent such an issue in the future.

I'm pretty sure there's a solution to this, but I'm having issues finding it, and I reckon this is an easy one for you guys :)

Thanks

0 likes
4 replies
Ben Taylor's avatar

I personally find it safer to leave default laravel tables as they are and work around them as best I can when there is a conflict.

If I have a Job model, then I just set the adjusted table name for my model like so:

protected $table = 'my_job_table_name';
cvikcangle's avatar

@Ben Taylor I agree to an extent. It's ok for new projects. But imagine having 20+ related tables around Jobs, and then it's inconsistent with names, and one's OCD can blow a fuse, cause a stroke or worse ;)

puklipo's avatar
puklipo
Best Answer
Level 9

For fresh Laravel11. Don't run this on existing projects.

Rename all tables name in migrations.

Schema::create('prefix_jobs', function (Blueprint $table) {

Schema::create('prefix_cache', function (Blueprint $table) {

Edit all table in config or .env

// config/queue.php
        'database' => [
            'table' => env('DB_QUEUE_TABLE', 'prefix_jobs'),
// config/cache.php
        'database' => [
            'table' => env('DB_CACHE_TABLE', 'prefix_cache'),
// .env
DB_QUEUE_TABLE=prefix_jobs
DB_CACHE_TABLE=prefix_cache

Re-create tables.

php artisan migrate:fresh
1 like

Please or to participate in this conversation.