1

Class Database\Factories\Tasks\UserFactory located in ./database/factories/tasks/UserFactory.php does not comply with psr-4 autoloading standard. Skipping.

This is my php file:

<?php

namespace Database\Factories\Tasks;

use App\Models\Tasks\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

class UserFactory extends Factory
{
  ...
}

Located in: database/factories/tasks/

Can someone explain me why this doesnt comply with psr-4 autoloading standard?

João Hamerski
  • 461
  • 1
  • 5
  • 22

2 Answers2

4

PSR-4 Autoload Standard is case sensitive. So If your Namespace starts with an Uppercase, your Folder name should do this also.

In your example, the directory should be Database/Factories/Tasks.

  • Are you sure? If i remove the `tasks` folder it just works fine, for example, i change the namespace to `Database\Factories\UserFactory.php` and the folder still is lowercase `database/factories/UserFactory.php` (works ok, no errors), it only happens if i add another folder to the `factories` folder, so it doesnt make sense. – João Hamerski Mar 14 '21 at 14:18
  • What is your PSR-4 Configuration in your composer.json? Have a look at https://github.com/composer/composer/blob/master/src/Composer/Autoload/ClassMapGenerator.php#L188 There is the comparison. Based on your answer i assume that Database\Factories is directly mapped to the path. But Task is then the additional folder which needs to be Upper Case for the first Letter. – Dennis Wandke Mar 15 '21 at 15:18
  • @JoãoHamerski Case insensitivity may be related to the os you are using. Windows does not care whilst a UNIX based system does to the very last letter – Richard Muvirimi May 19 '22 at 14:54
  • I was able to resolve the same problem by renaming the child directories only. E.g. `database/Factories/Tasks` – We'll See Apr 27 '23 at 14:37
1

Change this line in your composer.json file from this

"autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "Database/Factories/",
        "Database\\Seeders\\": "Database/Seeders/"
    }
},

to

 "autoload": {
    "psr-4": {
        "App\\": "app/",
        "Database\\Factories\\": "Database/Factories/Task",
        "Database\\Seeders\\": "Database/Seeders/"
    }
},
Matthew
  • 179
  • 1
  • 6