Skip to content

Instantly share code, notes, and snippets.

@thehelvetian
Forked from luckys383/UsersController.php
Created June 14, 2019 01:17
Show Gist options
  • Save thehelvetian/71e1aa0c468e884a7b3c293a38a32a3e to your computer and use it in GitHub Desktop.
Save thehelvetian/71e1aa0c468e884a7b3c293a38a32a3e to your computer and use it in GitHub Desktop.
Laravel: Common Filters using Model Scope
<?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