Category: Laravel

Attempting to utilise the new class based factories had me scratching my head for the best part of an afternoon. In the background Laravel is looking in the application Factories folder and so doesn’t see the ones in your package.

If you want to go down the rabbit hole start in Illuminate\Database\Eloquent\Factories\HasFactory trait and follow it to Illuminate\Database\Eloquent\Factories speciallycheck out resolveFactoryName on Line 680 Illuminate\Database\Eloquent\Factoriesfor a . There are two approaches which I’ve had success with.

Within the Models you wish to have Factories you add the following method with the full path to the Models Factory.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners