I know how to use paginate in laravel , but now I want use paginate() with selected columns only . this is my pagination code:
$data['users']=DB::table('users')->paginate(2);
this the sql statement I'm trying to get with paginate.
select id,name,username,email,groupName,lastSignIn from users;
my laravel code for this select statement:
$data['users']=DB::select('select id,name,username,email,groupName,lastSignIn from users;')->paginate(4);
but it's not working with me?
You may try this snippet code:
$user = User::paginate(5,['id','name','username'.....]);
This is what you need:
// Query\Builder
DB::table('users')
->select('id', 'name', 'username', 'email', 'groupName', 'lastSignIn')
->paginate(4);
And this:
DB::select(...);
is completely different method of another class (Connection
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With