Skip to content

Instantly share code, notes, and snippets.

@luckys383
Last active June 14, 2019 01:17
Show Gist options
  • Save luckys383/ad7d0b01e104a63cdd2a963f64f9e87c to your computer and use it in GitHub Desktop.
Save luckys383/ad7d0b01e104a63cdd2a963f64f9e87c 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