Answer the question
In order to leave comments, you need to log in
What is the practical meaning of the firstOrCreate() function (it's better to do findOrCreate())?
Hello.
Can you give a real example when the firstOrCreate() function is needed?
It's just that I'm bewildered: it seems to me it would be more logical to do findOrCreate () (which, as I understand it, does not exist at all).
Why such an emphasis on first?
That is, you usually make a request and if you don’t find it, then you create it, right?
find Or Create :)
And why first instead of find?
I don't get the logic.
Thank you.
Answer the question
In order to leave comments, you need to log in
Because there is already a method find()
that searches STRICTLY by id and returns one model, while firstOrCreate()
searching by ..? correctly, by a set of attributes, and as a result, there may be several models. Therefore, such an emphasis. It is enough to open the code of the method and think a little.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question