灯泡服务器中的碳丢错误

灯泡服务器中的碳丢错误

问题描述:

Laravel is throwing Class Carbon not found, I created the application in local environment and it's working, but when I deployed it to digitalocean server, it doesn't seem to work. here is the code:

{{ \Carbon\Carbon::parse($entity['start_date'])->format('d') }}

And we also tried:

{{ Carbon::parse($entity['start_date'])->format('d') }}

And here is the error it throws:

Class 'Carbon' not found (View: /var/www/html/resources/views/common/components/single_slider_event.blade.php) (View:

And the alies is set up correctly:

'aliases' => [
      'Carbon' => Carbon\Carbon::class,
],

Any help is appreciated in advance.

I solved the issue by running the following commands, it seems like even if you run composer install it might not work in the public environment.

composer update
php artisan config:clear
php artisan cache:clear 
composer dumpautoload
php artisan cache:clear

good luck!

You need to install those packages if they are not present on your production environment :

run composer install

Plus, make sure vendor has right file/folder owner and permissions.

If you have recently migrated, it will be a good time to clear any cache left :

run php artisan config:clear && php artisan cache:clear

An additional suggestion : If possible try to format the data prior to sending it to blade. Using date formatting in blade file is not at all wrong. But it's cleaner way to let controller do these things and blade just use them directly as much as possible.