You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I do think a recycle() method, similar to what Laravel factories provide could be useful.
While reading some blog posts about it, I figured out that one of its usage is basically when we do something like Contact::new(['address' => AddressFactory::createOne())->many(5)->create(), and I'm not interested about this part of the feature.
What I like about it, is that it forces to reuse deeply the same object, for every ManyToOne relationship.
Given their example with Airline, Flight, and Ticket models, where the ticket belongs to an airline and a flight, and the flight also belongs to an airline, the following code will create only one Airline, and use it both for Ticket::$airline relationship and for Flight::$airline relationship:
But I don't know if in this case, we should ensure the integrity of the data and always pick the same airline for both the ticket and its flight. I'm tempted to say "yes", because for me the whole point of this recycle() method would be to ensure integrity of the model. As far as I understand, this would differ from Laravel's recycle() method, where they always pick data randomly from the recycle collection.
I do think a
recycle()
method, similar to what Laravel factories provide could be useful.While reading some blog posts about it, I figured out that one of its usage is basically when we do something like
Contact::new(['address' => AddressFactory::createOne())->many(5)->create()
, and I'm not interested about this part of the feature.What I like about it, is that it forces to reuse deeply the same object, for every
ManyToOne
relationship.Given their example with
Airline
,Flight
, andTicket
models, where the ticket belongs to an airline and a flight, and the flight also belongs to an airline, the following code will create only oneAirline
, and use it both forTicket::$airline
relationship and forFlight::$airline
relationship:As far as I understand how it works,
recycle()
only applies for*ToOne
relationships.It also accepts a collection of objects:
But I don't know if in this case, we should ensure the integrity of the data and always pick the same airline for both the ticket and its flight. I'm tempted to say "yes", because for me the whole point of this
recycle()
method would be to ensure integrity of the model. As far as I understand, this would differ from Laravel'srecycle()
method, where they always pick data randomly from the recycle collection.any thought @kbond ?
The text was updated successfully, but these errors were encountered: