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.

v0.3 2015-02-10 09:54 UTC

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