134

I have built some migration classes in my application to create the tables I need, but I keep getting errors. I need to run this command:

composer dump-autoload

Only then it works again as expected. Am I doing something wrong that generates this error or this is a normal behaviour with migrations?

Below is the error that I get when running the migration process:

  [Symfony\Component\Debug\Exception\FatalErrorException]  
  Class 'CreateVideoStatusTable' not found  
szaman
  • 2,159
  • 1
  • 14
  • 30
Hasan Al-Natour
  • 1,936
  • 2
  • 14
  • 22
  • are you using phpartisan for migrations? – Duenna Nov 28 '15 at 17:15
  • yes i am using it to generate the create table and to run the migration – Hasan Al-Natour Nov 28 '15 at 17:16
  • do you have use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; inside your file and are extending the Migration class? – Duenna Nov 28 '15 at 17:17
  • yes , using "use Illuminate\Database\Schema\Blueprint" and "use Illuminate\Database\Migrations\Migration". – Hasan Al-Natour Nov 28 '15 at 17:18
  • Typically when I create migration files, they look similar to this http://codeshare.io/3iRxd take a look and see if yours follows a similar pattern, if you aren't you need to make sure that you are extending the Migration class. does everything look ok? – Duenna Nov 28 '15 at 17:20
  • framework can't handle delete file , from composer but ide can handle that , you can read autoload (PSR-0 & PSR-4) to better understand this issue – Honarkhah Oct 25 '17 at 13:39
  • https://stackoverflow.com/questions/37238547/run-composer-dump-autoload-from-controller-in-laravel-5/65718344#65718344 – pankaj Jan 14 '21 at 11:47

4 Answers4

136

OK so I think i know the issue you're having.

Basically, because Composer can't see the migration files you are creating, you are having to run the dump-autoload command which won't download anything new, but looks for all of the classes it needs to include again. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php), and this is why your migration is working after you run that command.

How to fix it (possibly) You need to add some extra information to your composer.json file.

"autoload": {
    "classmap": [
        "PATH TO YOUR MIGRATIONS FOLDER"
    ],
}

You need to add the path to your migrations folder to the classmap array. Then run the following three commands...

php artisan clear-compiled 
composer dump-autoload
php artisan optimize

This will clear the current compiled files, update the classes it needs and then write them back out so you don't have to do it again.

Ideally, you execute composer dump-autoload -o , for a faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticable).

Hope you can manage to get this sorted, as its very annoying indeed :(

Irfan
  • 7,029
  • 3
  • 42
  • 57
Duenna
  • 2,186
  • 2
  • 14
  • 17
12

You should run:

composer dump-autoload

and if does not work you should re-install composer

mpen
  • 272,448
  • 266
  • 850
  • 1,236
5

Short answer: classmaps are static while PSR autoloading is dynamic.

If you don't want to use classmaps, use PSR autoloading instead.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
4

My error was placing a function inside config/fortify.php, in my case it was an anonymous function that gave the error.

The definitive solution for this is to see what files I normally modify in the config/ folder.

In many places they say delete the files from bootstrap/cache/* but it didn't work in my case, and it didn't really make sense. In any case I leave you the commands:

php artisan clear-compiled
composer dump-autoload
php artisan optimize

But I really recommend that you go through the base laravel config files that you have configured. here you will find the error.

fafaaf
  • 129
  • 1
  • 2
  • Hi, I hoped you could clarify, because I think I may be having a similar issue. Do you mean that having an anonymous function _at all_ is not allowed in the config files? Or just that the function had a bug and that's why it wasn't working? Thanks! – Charles Wood Dec 29 '22 at 16:43