-
-
Save thehelvetian/71e1aa0c468e884a7b3c293a38a32a3e 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