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 noticed that the naming of this method is confusing to junior devs, because it is not consistent with ::make() (which exists both on Builder and HasOneOrMany) and ::create() on the model itself. Therefore it is not obvious what ->firstOrNew() really does.
Solution
I propose to rename firstOrNew() to firstOrMake() to be consistent with the corresponding model methods. Since this is a breaking change, the transition could be made smoother by adding firstOrMake() and deprecating firstOrNew() in 9.x, and only dropping firstOrNew() in 10.x.
PS: Maybe there's an import difference between firstOrNew() and make() that justifies the different naming.
Background
There are four classes that have a
firstOrNew()method:Illuminate\Database\Eloquent\BuilderIlluminate\Database\Eloquent\Relations\BelongsToManyIlluminate\Database\Eloquent\Relations\HasManyThroughIlluminate\Database\Eloquent\Relations\HasOneOrManyProblem
I noticed that the naming of this method is confusing to junior devs, because it is not consistent with
::make()(which exists both onBuilderandHasOneOrMany) and::create()on the model itself. Therefore it is not obvious what->firstOrNew()really does.Solution
I propose to rename
firstOrNew()tofirstOrMake()to be consistent with the corresponding model methods. Since this is a breaking change, the transition could be made smoother by addingfirstOrMake()and deprecatingfirstOrNew()in 9.x, and only droppingfirstOrNew()in 10.x.PS: Maybe there's an import difference between
firstOrNew()andmake()that justifies the different naming.