Why do I have to run composer dump-autoload command to make migrations work in laravel?
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 :(
Run composer dump-autoload from controller in laravel 5
Artisan is not wrapper for composer
. Composer itself brings the composer
command to control itself.
Currently there is no way to call composer
commands in a proper way from Artisan - not even with creating your own Artisan command with php artisan make:console CommandName
.
Unless you don't want to use PHPs exec
or system
, which I highly do not recommend, you better run composer dump-autoload
on its own.
Task of composer dump-autoload
I guess you're asking about why do you need to run this command after creating a new migration file. This command will just recreate a list of autoloaded classes so Laravel could load this migration file. In other words, you're kind of registering the migration class.
http://developed.be/2014/08/29/composer-dump-autoload-laravel/
What are the Differences Between php artisan dump-autoload and composer dump-autoload?
Laravel's
Autoload
is a bit different:
It will in fact use
Composer
for somestuff
It will call
Composer
with the optimizeflag
It will '
recompile
' loads of files creating the hugebootstrap/compiled.php
And also will find all of your Workbench packages and
composer dump-autoload
them, one by one.
Can not run Seeding on Laravel
You should try using composer dump-autoload
.
From this answer in SO:
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.
Related Topics
Concatenation with Addition in It Doesn't Work as Expected
Unit Testing and Static Methods
Best Practice: Import MySQL File in PHP; Split Queries
When *Not* to Use Prepared Statements
Continue Processing After Closing Connection
Counting Occurrence of Specific Value in an Array with PHP
Accessing Variables and Methods Outside of Class Definitions
Php: Check If Variable Exist But Also If Has a Value Equal to Something
Detect MySQL Update/Insertion Failure Due to Violated Unique Constraint
How to Decode Eval( Gzinflate( Base64_Decode(
Mysqli_Query() Expects at Least 2 Parameters, 1 Given In
PHP APIs for Hotmail, Gmail and Yahoo
Display Data from SQL Database into PHP/ HTML Table
What Security Issues Should I Look Out for in PHP
Guzzle: Handle 400 Bad Request
In PHP, What Is the Differences Between Null and Setting a String to Equal 2 Single Quotes
Passing Multiple PHP Variables to Shell_Exec()
Why Is It Whenever I Use Scandir() I Receive Periods at the Beginning of the Array