$user = User::where([ 'name' => $name, 'email' => $email ])->firstOr(function () use ($name, $email) { return User::create([ 'name' => $name, 'email' => $email, 'password' => bcrypt(Str::random(12)) ]); });