I'm overriding the create method on a few of my models, like in this question. The problem I'm finding is that factories for these models fail because they aren't calling my custom create method.
Model code:
class Teacher extends Model {
public static function create(array $attributes)
{
$user = User::create(['name' => $attributes['name']);
return static::query()->create(['budget' => $attributes['budget', 'user_id' => $user->id]);
}
Factory code:
$factory->define(App\Teacher::class, function(Faker $faker) {
return [
'name' => $faker->firstName(),
'budget' => $faker->numberBetween(100, 1000)
];
}
I get the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list' (SQL: insert into `teachers` (`name`, `budget`, `updated_at`, `created_at`) values (Audreanne, 600, 2020-04-07 16:43:54, 2020-04-07 16:43:54))
Any help is greatly appreciated!
budgetcolumn does not appear to exist in yourteacherstable are you sure you have migrated it?