Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/assembleonline/eloquentsearch
Searching facility to recursively search relations defined in Laravel5 Eloquent ORM
https://github.com/assembleonline/eloquentsearch
eloquent laravel laravel5 search
Last synced: about 1 month ago
JSON representation
Searching facility to recursively search relations defined in Laravel5 Eloquent ORM
- Host: GitHub
- URL: https://github.com/assembleonline/eloquentsearch
- Owner: AssembleOnline
- Created: 2016-02-24T09:48:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-02-28T09:56:54.000Z (over 5 years ago)
- Last Synced: 2024-10-13T02:21:45.989Z (about 1 month ago)
- Topics: eloquent, laravel, laravel5, search
- Language: PHP
- Size: 15.6 KB
- Stars: 1
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Eloquent Model Searcher for Laravel 5
## Installation
Add this line to your `providers` array:
``` php
Assemble\EloquentSearch\EloquentSearchServiceProvider::class,
```Add this line to your `aliases` array:
``` php
'EloquentSearch' => Assemble\EloquentSearch\Facades\EloquentSearcher::class,
```
You will need to run `php artisan vendor:publish` to publish the config file to your instalation,
Once run, you can find it in `config/eloquenet_search.php`.
This config file is used to controll which models are used to search/return entities of.## Configuration
The config file can be found in the laravel config folder at `config/eloquent_search.php`,
here you can define the classes related to your models as below.
``` php
return [
'search_models' => [
/*
Add your searchable eloquent models here, this is an example of user model usage.If you have your models sitting in the app root as default, something like this should find them.
'user' => User::class,
Otherwise if you have them elsewhere or the application cant seem to find them, try prefix them as such.
'user' => App\Models\User::class,*/
'user' => User::class,]
];
```## Usage
To make use of the search functionality, you will need to implement a `$searchable` property on your models to detail which fields and relations are searchable.
```php
/*
* Searchable Fields
*/
public $searchable = [
'name', 'user_id', // fields
'user', 'tags', // relations
];
```You can also implement the method 'isSearchable' in your models for the searcher to determine if it is allowed to search/return that model.
``` php
public function isSearchable(){
// Do your checks to determine if the model may be searched by the user
return true;
}
```
This feature lets you restrict user searches to only the models they are allowed to see.