Get model column value in Laravel and new whereKey method in Laravel 5.4
In some cases we want to get Eloquent model single column value based on other column value. Let’s assume we have user id and we want to get his e-mail only. We can obviously do:
1 2 |
$user = User::find($id); $email = $user->email; |
or even shorter:
1 |
$email = User::find($id)->email; |
but there is one big problem with this – what if user doesn’t exist? Obviously … [Read more…]