1

I have a project where laravel was migrated from 7 to 9 version

Models are stored in

app/v2/

folder

Factories are stored in

database/factories/v2

folder

In my composer I have

"psr-4": {
    "MyApi\\": "app/",
    "Database\\Factories\\": "database/factories/"
    ...
}

My example model

namespace MyApi\v2;

class Test extends Model
{
    use HasFactory;

has example factory

namespace Database\Factories\v2;

use MyApi\v2\Test;

class TestFactory extends Factory
{
    protected $model = Test::class;

With this setup everything works good.

But tell me please - is it any way to make it works without adding

protected $model

part in factory? Now if I remove it I am getting

Error: Class "MyApi\Test" not found

If I move model to "app/" folder and factory to "database/factories" folder everything works well without protected $model part in factory. But I need models be stored in "app/v2" folder.

Alex
  • 11
  • 2
  • Check this https://stackoverflow.com/questions/63473364/how-to-use-a-custom-class-in-laravel-when-it-is-in-a-sub-folder – OMi Shah Nov 02 '22 at 16:35

0 Answers0