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.
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 :(
Laravel, dump-autoload without Shell Access
You dont need shell access. Artisan includes a dump-autoload
function. You can just it via a PHP call within your app:
Route::get('/updateapp', function()
{
\Artisan::call('dump-autoload');
echo 'dump-autoload complete';
});
Edit: just noticed you wrote "composer isn't installed on the server anyway". Not sure what will happen - try the command above and let us know.
If it doesnt work - then just run composer dump-autoload locally - then upload your new autoload.php.
As a side point - is there any option to switch servers? You going to keep running into various issues if you dont have command line & composer access. You could just use Forge and spin up a new server on DigitalOcean, Linode etc in less time than it would take to fix this issue :)
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/
why need to composer dump-autoload
There are many options for you to setup composer's autoload behaviours.
I'd recommend using psr-4
autoloading, for example:
...
"autoload": {
// The rest of your composer autoload
// add your namespace below
"psr-4": [
"Foo\\" : "app/Foo"
]
},
...
What this does is simply telling composer that you are following PSR-0/PSR-4 convention on structuring your folder/directory according to your namespace. You'll need to do composer dump-autoload
for this to work the first time, but it'll pick new modules up automatically the next time without dump-autoload
.
Read more on PSR guidelines here: PSR-0 and PSR-4
Amazing laracasts by Jeffrey Way: https://laracasts.com/lessons/psr-4-autoloading
How do I force composer dump-autoload to start from scratch?
It always runs from "scratch". But I guess that if you want to be extra sure, you can simply delete the previously generated files.
The created files are vendor/autoload.php
and some on vendor/composer
, so you could delete them manually before re-dumping the autoloader.
These are the contents of that directory fresh out of a composer install --no-autoloader
:
└── vendor/
└── composer/
├── semver/
├── xdebug-handler/
├── installed.json
└── LICENSE
And these are its contents after running composer dump-autoload
:
├── vendor/
│ └── composer/
│ ├── semver/
│ ├── xdebug-handler/
│ ├── autoload_classmap.php
│ ├── autoload_files.php
│ ├── autoload_namespaces.php
│ ├── autoload_psr4.php
│ ├── autoload_real.php
│ ├── autoload_static.php
│ ├── installed.json
│ └── LICENSE
└── autoload.php
So you basically need just to delete
vendor/autoload.php
vendor/composer/autoload_*
vendor/composer/ClassLoader.php
And you can rerun composer dump-autoload
from a pristine starting point.
Related Topics
How to Run Composer from Anywhere
Supplied Argument Is Not a Valid MySQL Result Resource
Simple Form Not Sending Data via _Post
Best Way to Document Array Options in PHPdoc
Send Email with a Template Using PHP
Generating a Waveform Using Ffmpeg
Location for Session Files in Apache/Php
Forbidden :You Don't Have Permission to Access /Phpmyadmin on This Server
Instagram Login Programmatically
How to Store Configuration Variables in PHP
Check If a Remote Page Exists Using PHP
How to Manually Return or Throw a Validation Error/Exception in Laravel
Laravel Use Same Form for Create and Edit
Cannot Pass Null Argument When Using Type Hinting