Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nahidulhasan/eloquent-filter
This simple package helps you filter Eloquent data using query filters.
https://github.com/nahidulhasan/eloquent-filter
eloquent filter laravel orm
Last synced: about 9 hours ago
JSON representation
This simple package helps you filter Eloquent data using query filters.
- Host: GitHub
- URL: https://github.com/nahidulhasan/eloquent-filter
- Owner: nahidulhasan
- Created: 2019-08-31T15:18:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-08T11:51:05.000Z (about 5 years ago)
- Last Synced: 2024-10-08T10:56:54.348Z (about 1 month ago)
- Topics: eloquent, filter, laravel, orm
- Language: PHP
- Homepage:
- Size: 11.7 KB
- Stars: 25
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel Eloquent Filter
[![Latest Stable Version](https://poser.pugx.org/nahidulhasan/eloquent-filter/v/stable)](https://packagist.org/packages/nahidulhasan/eloquent-filter)
[![Total Downloads](https://poser.pugx.org/nahidulhasan/eloquent-filter/downloads)](https://packagist.org/packages/nahidulhasan/eloquent-filter)
[![Latest Unstable Version](https://poser.pugx.org/nahidulhasan/eloquent-filter/v/unstable)](https://packagist.org/packages/nahidulhasan/eloquent-filter)
[![License](https://poser.pugx.org/nahidulhasan/eloquent-filter/license)](https://packagist.org/packages/nahidulhasan/eloquent-filter)
This simple package helps you filter Eloquent data using query filters.
## Installation
Run the following command:
```
$ composer require nahidulhasan/eloquent-filter
```
## Getting started
Use the trait `NahidulHasan\EloquentFilter\Filterable` in your eloquent model.Create a new class by extending the class `NahidulHasan\EloquentFilter\QueryFilters` and define your custom filters as methods with one argument. Where function names are the filter argument name and the arguments are the value.
Let's assume you want to allow to filter articles data. Please see the following code.
```php
builder->where('title', 'like', '%' .$title.'%');
}
}
```
With this class we can use the http query string : `title=article_name` or any combination of these filters. It is up to you to define if you will use AND wheres or OR.Now in the controller you can apply these filters like as described in below :
```php
paginate(5);
return view('articles.index', compact('articles'))->with('i', (request()->input('page', 1) - 1) * 5);
}
}
```If you go to this link you will get all code:
https://github.com/nahidulhasan/laravel-eloquent-query-filtering### Thanks to :
https://github.com/laracasts/Dedicated-Query-String-Filtering
### License
Eloquent-Filter for Laravel is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)