php - How to determine columns that will be returned in the result when using `paginate()` method in Laravel?
I have 2 tables:users
andarticles
. To fetch all columns from thearticles
table and onlyuser_name
column from theusers
table, I use this code:
$articles = Article::join('users', 'articles.user_id', '=', 'users.user_id')
->get(array('articles.*', 'users.user_name'));
and it works fine, but when I usepaginate()
method like this:
$articles = Article::join('users', 'articles.user_id', '=', 'users.user_id')
->paginate(10);
it fetches all columns from both tables, which I don't want. My question is: How can I select columns that will be returned in the result if I usepaginate()
method in Laravel framework?
Answer
Solution:
The select function does this.