Skip to content
Robert Askam

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

Robert Askam 1 min read 1,977 views

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

Category 1 laravel model relation