remoblaser / search
A simple to implement Search for your Application
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 1 509
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=5.4.0
- illuminate/support: 5.*
This package is not auto-updated.
Last update: 2023-03-04 07:27:20 UTC
README
Install With Composer
"require": { "remoblaser/search": "^0.3.0" }
Configure the app
Add the service provider to config/app.php
.
'providers' => array( ... 'Remoblaser\Search\SearchServiceProvider', ),
Register the alias in the app/config/app.php
file.
'aliases' => array( ... 'Search' => 'Remoblaser\Search\Facades\Search' ),
Publish the configuration
php artisan vendor:publish
Usage
After publishing the config, you will find a config file under app/packages/remoblaser/search/config.php
, bind your Models to a key here, if you have a Posts
table for example, add it here:
return array( 'users' => 'User', 'posts' => 'My\Sample\Namespace\Post' );
Afterwards you have to implement the SearchableTrait in your Model and define the Fields which you would like to search. In this example i would like to search through the titles and the bodies.
<?php namespace My\Sample\Namespace; use Remoblaser\Search\SearchableTrait; class Post extends \Eloquent{ use SearchableTrait; protected $searchFields = ['title', 'body']; }
Now you can Search through your Tables from anywhere in your application by using the Search Facade, followed by the binding key.
Search::posts('bla')
Or you could search all registered Tables for the Keyword.
Search::all('bla')
Feel free to make pull requests, this is my first laravel package so im sure i did things badly