I have tried multiple ways to call below method in the model
public function getFullNameAttribute()
{
return "{$this->first_name} {$this->last_name}";
}
What I tried:
User::select('first_name', 'last_name')
->with([
'fullName' => function($query){
$query->select(DB::raw("CONCAT(first_name, ' ', last_name) AS full_name"));
}
])
->where('user_id', $id)
->where('is_deleted', 0)
->first();
Another way I tried:
User::select(DB::raw("CONCAT(first_name, ' ', last_name) AS full_name"))
->with([
'fullName' => function($query){
$query->select('firstname', 'lastname');
}
])
->where('user_id', $id)
->where('is_deleted', 0)
->first();
But nothing is calling get<>Attribute name.
firstnameandfirst_name- which is it?