2,181
views
views
Eloquent has quite a few functions that combine two methods, like “please do X, otherwise do Y”.
firstOrCreate()
Instead of:
$user = User::where('email', $email)->first();if (!$user) { User::create([ 'email' => $email ]);}
Do just this:
$user = User::firstOrCreate(['email' => $email]);
Comments
0 comment