Last active
June 14, 2019 01:17
-
-
Save luckys383/ad7d0b01e104a63cdd2a963f64f9e87c to your computer and use it in GitHub Desktop.
Laravel: Common Filters using Model Scope
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Controller; | |
use App\User; | |
use Illuminate\Http\Request; | |
class UsersController extends Controller | |
{ | |
protected $model; | |
public function __construct(User $model) | |
{ | |
$this->model = $model; | |
} | |
public function index(Request $request) | |
{ | |
$users = $this->model | |
->filter($request->all()) | |
->get(); | |
return view('users.index', [ | |
'users' => $users | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment