I want to get an instance of an Eloquent model record based on a specific column that it is not the pk
.
So in the controller I'm doing:
$boat = Boat::getByBoatName($boatName);
And in the Boat
model I have:
public static function getByBoatName($boatName)
{
return self::where('boat_name', $boatName)->first();
}
Is this a good practice using self::where
and it is a good practice the whole approach in general?
Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…