Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel, dump-autoload without Shell Access

I have two controllers with the same name:

app\controllers\CareersController.php (for public use) app\controllers\Admin\CareersController.php (for admins)

Because of the naming conflict, I added namespace admin; to the admin controller.

Everything works fine locally but when I uploaded the new admin controller to my server, I get an error: Class Admin\CareersController does not exist

From what I understand, the fix is: php artisan dump-autoload and composer dump-autoload

However, I don't have Shell access to run those commands and composer isn't installed on the server anyway. So, is there a way to reload the auto-load file without Shell access?

like image 353
Justin Avatar asked Sep 29 '14 22:09

Justin


3 Answers

Run composer dump-autoload locally. Then, in your hosting site, you can update two files, autoload_classmap.php and autoload_static.php, manually in vendor/composer folder. I prefer to copy and paste the added classes from local to the hosting server.

like image 58
user10971804 Avatar answered Nov 17 '22 07:11

user10971804


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

like image 38
Laurence Avatar answered Nov 17 '22 05:11

Laurence


I was using a shared hosting by client's requirements and did not have access to ssh or composer, what I did was to composer dump-autoload on my local machine and then I figured that for my project autoloader just updates composer directory in my vendor directory, so I just re-uploaded that one folder after each dump-autoload and not all vendor directory

Edit:

Another pitfall for me that generated the same error but the cause was something else, I develop on Windows machine in which file and directory names are case insensitive when deploying to Linux server, the framework could actually not find my controllers so I changed

Route::get('/news', 'newsController@index');

to

Route::get('/news', 'NewsController@index');

now it is working, autoload is doing it's job correctly

like image 2
mohas Avatar answered Nov 17 '22 06:11

mohas