Laravel - execute a relation model factory only when the relational id is not present

Laravel - execute a relation model factory only when the relational id is not present

Reference

 

In a factory you can execute a relation model factory only when the relational id is not present by doing this. If the user_id exists in the attributes it will not execute the callback, otherwise it will.

 

Relation Insert

Categories: Category 1