|
| 1 | +# Laravel Cross Eloquent Search |
| 2 | + |
| 3 | +[](https://packagist.org/packages/protonemedia/laravel-cross-eloquent-search) |
| 4 | +[](https://travis-ci.org/pascalbaljetmedia/laravel-cross-eloquent-search) |
| 5 | +[](https://scrutinizer-ci.com/g/pascalbaljetmedia/laravel-cross-eloquent-search) |
| 6 | +[](https://packagist.org/packages/protonemedia/laravel-cross-eloquent-search) |
| 7 | + |
| 8 | +## Requirements |
| 9 | + |
| 10 | +* PHP 7.4+ |
| 11 | +* MySQL 5.7+ |
| 12 | +* Laravel 6.0 / 7.0 |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +You can install the package via composer: |
| 17 | + |
| 18 | +```bash |
| 19 | +composer require protonemedia/laravel-cross-eloquent-search |
| 20 | +``` |
| 21 | + |
| 22 | +## Configuration |
| 23 | + |
| 24 | +No configuration! |
| 25 | + |
| 26 | +## Usage |
| 27 | + |
| 28 | +### Basic |
| 29 | + |
| 30 | +```php |
| 31 | +$results = Search::new() |
| 32 | + ->add(Post::class, 'title') |
| 33 | + ->add(Video::class, 'title') |
| 34 | + ->get('foo'); |
| 35 | +``` |
| 36 | + |
| 37 | +### Pagination |
| 38 | + |
| 39 | +```php |
| 40 | +$results = Search::new() |
| 41 | + ->add(Post::class, 'title') |
| 42 | + ->add(Video::class, 'title') |
| 43 | + |
| 44 | + ->paginate() |
| 45 | + // or |
| 46 | + ->paginate($perPage = 15, $pageName = 'page', $page = 1) |
| 47 | + |
| 48 | + ->get('foo'); |
| 49 | +``` |
| 50 | + |
| 51 | +### Scoped queries |
| 52 | + |
| 53 | +```php |
| 54 | +$results = Search::new() |
| 55 | + ->add(Post::published(), 'title') |
| 56 | + ->add(Video::where('views', '>', 2500), 'title') |
| 57 | + ->get('foo'); |
| 58 | +``` |
| 59 | + |
| 60 | +### Multiple columns |
| 61 | + |
| 62 | +```php |
| 63 | +$results = Search::new() |
| 64 | + ->add(Post::class, ['title', 'body']) |
| 65 | + ->add(Video::class, ['title', 'subtitle']) |
| 66 | + ->get('foo'); |
| 67 | +``` |
| 68 | + |
| 69 | +### Order results |
| 70 | + |
| 71 | +```php |
| 72 | +$results = Search::new() |
| 73 | + ->add(Post::class, 'title', 'publihed_at') |
| 74 | + ->add(Video::class, 'title', 'released_at') |
| 75 | + ->orderByDesc() // optional |
| 76 | + ->get('foo'); |
| 77 | +``` |
| 78 | + |
| 79 | +### Testing |
| 80 | + |
| 81 | +``` bash |
| 82 | +composer test |
| 83 | +``` |
| 84 | + |
| 85 | +### Changelog |
| 86 | + |
| 87 | +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. |
| 88 | + |
| 89 | +## Contributing |
| 90 | + |
| 91 | +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. |
| 92 | + |
| 93 | +### Security |
| 94 | + |
| 95 | +If you discover any security related issues, please email pascal@protone.media instead of using the issue tracker. |
| 96 | + |
| 97 | +## Credits |
| 98 | + |
| 99 | +- [Pascal Baljet](https://github.com/protonemedia) |
| 100 | +- [All Contributors](../../contributors) |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments