I'm currently using eager loading in laravel and used the select()
method. However, when I tried to select the child table, it returns an error. Please see my code below.
Controller
$posts = Post::with('author');
$posts->select(['body', DB::raw('CONCAT(users.first_name, " ", users.last_name) as AUTHOR')]);
The code above returns this error:
Column not found: 1054 Unknown column 'users.first_name' in 'field list'
So I tried to make it like this:
$posts = Post::with('author');
$posts->select(['body', DB::raw('CONCAT(author.first_name, " ", author.last_name) as AUTHOR')]);
Now I used the relationship to get the first and last name but I'm getting the same error. Any idea?
UPDATE
I'm using laravel 5.2
for this project.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…