Search code examples
laravelnamespacescomposer-phpvagrantphp-carbon

Carbon file not found Vagrant


laravel/framework v5.5.37

I git cloned someone's project on my machine. Using Vagrant with Homestead box. I get this error: enter image description here

I have not made in changes to the code. On his environment it works and on production it works as well. When I search for Carbon, it is only in the composer.lock file, not the composer.json file. What does that mean? I thought that meant he had globally installed nesbot/carbon on his machine so when i did composer global require "nesbot/carbon" I still get the error.

How is it possible it is in lock but not in json? Im doing all of this in the vagrant ssh.


Solution

  • You need to import Carbon:

    use Carbon\Carbon;
    

    after declaring your namespace in controller.

    for example:

    <?php
    
    namespace App\Http\Controllers;
    
    use Carbon\Carbon; // here added the line
    

    It doesn't seem to be "your" fault, it seems like bug in code. Carbon is used by Laravel framework under the hood so you don't need to have it in your composer.json file .