anchan42's avatar

Table name crashing with Laravel factory method

I have got a table named fatories. There is another table with relationship below to the factories table.

public function factory()
{
    return $this->belongsTo(Factory::class);
}

This mathod's name crashing with the laravel factory method. It cause problem when I try to run factory to seed the database.

Is there a way to resolve this ?

0 likes
4 replies
tykus's avatar

Yes. Use a different relationship name.

1 like
anchan42's avatar

I was hoping I could rename the method from the trait but maybe not 🥲

tykus's avatar
tykus
Best Answer
Level 104

@anchan42 you can; but I don't know if you should:

use HasFactory {
	factory as modelFactory;
}

In the long run, sticking to the conventional use of factory in your tests will lead to less confusion IMHO

1 like

Please or to participate in this conversation.