Skip to content

Instantly share code, notes, and snippets.

@mehdi-fathi
Last active February 13, 2020 07:57
Show Gist options
  • Save mehdi-fathi/75b647d421aca420b9ed0c6ec781df6b to your computer and use it in GitHub Desktop.
Save mehdi-fathi/75b647d421aca420b9ed0c6ec781df6b to your computer and use it in GitHub Desktop.
UsersController
<?php
namespace App\Http\Controllers;
use eloquentFilter\QueryFilter\ModelFilters\ModelFilters;
/**
* Class UsersController.
*/
class UsersController
{
/**
* @param \eloquentFilter\QueryFilter\ModelFilters\ModelFilters $modelFilters
*/
public function list(ModelFilters $modelFilters)
{
if (!empty($modelFilters->filters())) {
$perpage = Request::input('perpage');
Request::offsetUnset('perpage');
$users = User::filter($modelFilters)->with('posts')->orderByDesc('id')->paginate($perpage,['*'],'page');
} else {
$users = User::with('posts')->orderByDesc('id')->paginate(10);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment