Jun 29, 2015
0
Level 7
Creating Pagination Options
I'm looking at creating a pagination to view my users, however I want to be able to view my users by all active, deleted (soft deleted), and all together.
I was wondering if there was any better way to approach this than what I am currently doing.
Admin/UsersController Controller
public function index(Request $request)
{
$allowed = [
'deleted' => 'onlyTrashed',
'all' => 'withTrashed'
];
$limit = $request->get('limit') ?: 10;
$users = array_key_exists($request->get('q'), $allowed)
? User::{$allowed[$request->get('q')]}()->paginate($limit)
: User::paginate($limit);
return view('admin.users.index', compact('users'));
}
Please or to participate in this conversation.