Model::paginate() and then ->append('attribute')

Posted 2 months ago by neeonline

Hello all,

I'm using Laravel's Database Pagination (https://laravel.com/docs/5.8/pagination#basic-usage), everything work fine...

I came to a dead-[I can't find it in Google]-end. So, let's get a User model with pagination:

$users = User::paginate(15);

If needed I can add query params to the links object:

$users = User::paginate(15)->appends(['queryParam' => 'paramValue']);

But I can't append an attribute to the result set, everything that I tried failed =(

$users = User::paginate(15)->append('userAttribute');

I know it's possible to add the attribute to the protected $appends array, but this append is based on security level. So not all users should see this value.

Any help is appreciate.

Thanks!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.