brunoquaresma/laravel-dbsearch

7 10
Install
composer require brunoquaresma/laravel-dbsearch:dev-master
PHP:>=5.3.0
Last Updated:May 29, 2014
Links: GitHub  ·  Packagist
Maintainer: BrunoQuaresma

LaravelDBSearch

A simple package for full text search using the Laravel's Eloquent.

  1. Required setup
  2. Basic usage
  3. Use join

Required setup

In the require key of composer.json file add the following

"brunoquaresma/laravel-dbsearch": "dev-master"

Run the Composer update comand

$ composer update

In your config/app.php add 'Brunoquaresma\LaravelDBSearch\LaravelDBSearchServiceProvider' to the end of the $providers array

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'Brunoquaresma\LaravelDBSearch\LaravelDBSearchServiceProvider',

),

At the end of config/app.php add 'LaravelDBSearch' => 'Brunoquaresma\LaravelDBSearch\Facades\LaravelDBSearch' to the $aliases array

'aliases' => array(

    'App'        => 'Illuminate\Support\Facades\App',
    'Artisan'    => 'Illuminate\Support\Facades\Artisan',
    ...
    'LaravelDBSearch' => 'Brunoquaresma\LaravelDBSearch\Facades\LaravelDBSearch'

),

###Basic usage

For this example we use a course model.

$courses =  LaravelDBSearch::model('Course')			
				->field(array('name', 'description'))
				->query('php')
				->get();
  1. model() - Set the default model for the search.
  2. field() - Set the search fields by array or a string value if have only one field.
  3. query() - Set the search query value.
  4. get() - Get the results of search.

###Use join

Get the courses where the owner have a name with John.

$courses =  LaravelDBSearch::model('Course')			
				->field(array('name', 'description', 'first_name', 'last_name', 'username'))
				->join('courses.*', 'users', 'courses.user_id', '=', 'users.id')
				->query('John')
				->get();

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

644,549,754 9,698
laravel/framework

The Laravel Framework.

598,760,099 34,966
laravel/tinker

Powerful REPL for the Laravel framework.

507,193,856 7,441
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

423,477,751 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

403,217,078 4,664