29/05
2014
Wallogit.com
2017 © Pedro Peláez
A simple package for full text search using the Laravel's Eloquent., (*1)
In the require key of composer.json file add the following, (*2)
"brunoquaresma/laravel-dbsearch": "dev-master"
Run the Composer update comand, (*3)
$ composer update
In your config/app.php add 'Brunoquaresma\LaravelDBSearch\LaravelDBSearchServiceProvider' to the end of the $providers array, (*4)
'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, (*5)
'aliases' => array(
'App' => 'Illuminate\Support\Facades\App',
'Artisan' => 'Illuminate\Support\Facades\Artisan',
...
'LaravelDBSearch' => 'Brunoquaresma\LaravelDBSearch\Facades\LaravelDBSearch'
),
For this example we use a course model., (*6)
$courses = LaravelDBSearch::model('Course')
->field(array('name', 'description'))
->query('php')
->get();
Get the courses where the owner have a name with John., (*7)
$courses = LaravelDBSearch::model('Course')
->field(array('name', 'description', 'first_name', 'last_name', 'username'))
->join('courses.*', 'users', 'courses.user_id', '=', 'users.id')
->query('John')
->get();