Specify Custom Factory Path
- Laravel
- Eloquent
Laravel automatically looks in the database/factories
for Factory classes, but you can specify any Factory for the model on the model itself like so:
1<?php 2 3namespace App\Models; 4 5use Database\Factories\UserFactory; 6use Illuminate\Foundation\Auth\User as Authenticatable; 7 8class User extends Authenticatable 9{10 // ...11 12 protected static function newFactory()13 {14 return new UserFactory();15 }16}