Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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)