PHP Fatal error: Cannot declare class , because the name is already in use – Laravel Migrations

Vincent Paul/ May 23, 2022/ Laravel, PHP, Programming, Technology

Please read our Disclaimer

Works with

-Laravel Framework 8.83.11

In case you have encountered something similar:

Try to do the following:

On your terminal, run the following command:

composer dump-autoload

If that doesn’t fix it, try to do the following:

  1. Make sure there are no existing duplicate class names in your migrations, the names are case in-sensitive, so Roles and roles will end up to be the same.
  2. Make sure the filenames are correct, the Laravel out-of-the-box migration naming convention follows yyyy_mm_dd_hhmmss_create_pluraltablenames_table.php.
    • 2022_05_18_123115_create_categories_table.php
    • In my experience, I tried something like create_categories_table.php, bypassing the conventions and ending up myself with the issue.

It may or may not be directly related, but in my case, that saved me a ton. HTH

UPDATE:

This can also be caused by having a different ClassName in your class filename and your table name.

Example: class CreateDepartmentTable vs. departments, noticed the missing “s” in the CreateDepartmentTable. The correct one should be CreateDepartmentsTable.

Share this Post