John Davidson

php - Laravel 7 Trait not found

0 comments
Message:


Hello I have problem when pushing my laravel project to the server with the Trait.



  • My project works perfectly on local but on server, when i try composer install I got the error Trait 'App\Traits\LoggedCommand' not found


This is my trait named LoggedCommand.php


<?php
namespace App\Traits;

use App\Services\TaskScheduleLoggerService;

trait LoggedCommand {
// code
}

And this is where i want to use the Trait i have registered


<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Services\ProductUpdaterService;
use App\Traits\LoggedCommand;

class updateProductsData extends Command
{

}

Any one knows about this problems? Thank you in advance!!!



My Answer:
It seems like the autoloader is not able to find the Trait file on the server.

You can try the following steps to resolve the issue:

1. Make sure that the file name and the namespace in the Trait file match exactly. In your case, the file name is LoggedCommand.php and the namespace is App\Traits.

2. Run `composer dump-autoload` command on the server to regenerate the autoloader files.

3. Check the file permissions on the server to ensure that the Trait file is readable by the server.

4. Check the case sensitivity of the file names and namespaces. Make sure that the file name and the namespace are in the correct case.

5. If the Trait file is located in a different directory than the default Laravel directory structure, you may need to update the composer.json file to include the custom directory in the autoload section.

After trying these steps, try running `composer install` again and see if the issue is resolved.

Rate this post

3 of 5 based on 6445 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us