RonasIT / laravel-empty-project

7 stars 2 forks source link

Add HasFactory trait to existed models #54

Closed Adil9994 closed 1 year ago

Adil9994 commented 1 year ago

Related task https://github.com/RonasIT/laravel-entity-generator/issues/20 Fix: Add HasFactoryTrait to models Related error:

php artisan make:entity Car

Created a new Model: Car Created a new Repository: CarRepository Created a new Service: CarService Created a new Request: GetCarRequest Created a new Request: SearchCarsRequest Created a new Request: DeleteCarRequest Created a new Request: CreateCarRequest Created a new Request: UpdateCarRequest Created a new Resource: CarResource Created a new Route: Route::post('cars', [CarController::class, 'create']); Created a new Route: Route::put('cars/{id}', [CarController::class, 'update']); Created a new Route: Route::delete('cars/{id}', [CarController::class, 'delete']); Created a new Route: Route::get('cars/{id}', [CarController::class, 'get']); Created a new Route: Route::get('cars', [CarController::class, 'search']); Created a new Controller: CarController Created a new Migration: cars_create_table Created a new Factory: CarFactory

InvalidArgumentException

Unable to locate factory for [App\Models\Media].

at vendor/laravel/legacy-factories/src/FactoryBuilder.php:273 269▕ */ 270▕ protected function getRawAttributes(array $attributes = []) 271▕ { 272▕ if (! isset($this->definitions[$this->class])) { ➜ 273▕ throw new InvalidArgumentException("Unable to locate factory for [{$this->class}]."); 274▕ } 275▕ 276▕ $definition = call_user_func( 277▕ $this->definitions[$this->class],

  +8 vendor frames 

9 [internal]:0 RonasIT\Support\Generators\TestsGenerator::RonasIT\Support\Generators{closure}("Media")

  +19 vendor frames 

29 artisan:23 Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)

@DenTray

DenTray commented 1 year ago

@Adil9994 that's good to add this trait but in a generator we should process such a case correctly without failing the process.

Adil9994 commented 1 year ago

@Adil9994 that's good to add this trait but in a generator we should process such a case correctly without failing the process.

@DenTray got it, i will create separate task for generator

Adil9994 commented 1 year ago

@DenTray done, pls check

DenTray commented 1 year ago

@Adil9994 works, thanks!