j-dexx / eloquent-ransack
Easily filter eloquent models
Installs: 1 081
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 3
Open Issues: 0
pkg:composer/j-dexx/eloquent-ransack
Requires
- illuminate/database: ^7.0|^8.0
- illuminate/support: ^7.0|^8.0
Requires (Dev)
- laravel/legacy-factories: ^1.0
- nesbot/carbon: ^2.39
- orchestra/testbench: ^6.0.0
This package is auto-updated.
Last update: 2025-10-09 20:24:01 UTC
README
Inspired by the ransack gem eloquent ransack's goal is to provide a simplistic filtering method on eloquent models.
Usage
The Ransackable trait provides a ransack scope that you pass an array of input to. All filters should be of the form column_name_predicate where predicate is one of the options listed in the table below.
Available Filtering Types
| predicate | example | sql |
|---|---|---|
| eq | name_eq | where "name" = ? |
| not_eq | name_not_eq | where "name" != ? |
| cont | name_cont | where "name" LIKE ? |
| in | category_id_in | where "category_id" in (?) |
| not_in | category_id_not_in | where "category_id" not in (?) |
| lt | date_lt | where "date" < ? |
| lte | date_lte | where "date" <= ? |
| gt | date_gt | where "date" > ? |
| gte | date_gte | where "date" >= ? |
Example
Eloquent Model
use Jdexx\EloquentRansack\Ransackable; class Post { use Ransackable; }
Form
<form> <input type="text" name="name_eq" /> </form>
Controller
class PostsController { public function index(Request $request) { $params = $request->all(); $posts = Post::ransack($params)->get(); } }