Why do I have to run “composer dump-autoload” command to make migrations work in laravel?

后端 未结 3 1475
你的背包
你的背包 2020-11-29 19:08

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-autoloa

相关标签:
3条回答
  • 2020-11-29 19:18

    You should run:

    composer dump-autoload
    

    and if does not work you should:

    re-install composer
    
    0 讨论(0)
  • 2020-11-29 19:31

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

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

    0 讨论(0)
  • 2020-11-29 19:35

    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 :(

    0 讨论(0)
提交回复
热议问题