PHP code example of technote / laravel-search-helper
1. Go to this page and download the library: Download technote/laravel-search-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
technote / laravel-search-helper example snippets
namespace App\Models;
use Eloquent;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Technote\SearchHelper\Models\Contracts\Searchable as SearchableContract;
use Technote\SearchHelper\Models\Traits\Searchable;
/**
* Class Item
* @mixin Eloquent
*/
class Item extends Model implements SearchableContract
{
use Searchable;
/**
* @var array
*/
protected $guarded = [
'id',
];
/**
* @param Builder $query
* @param array $conditions
*/
protected static function setConditions(Builder $query, array $conditions)
{
if (! empty($conditions['s'])) {
collect($conditions['s'])->each(function ($search) use ($query) {
$query->where(function ($builder) use ($search) {
/** @var Builder $builder */
$builder->where('items.name', 'like', "%{$search}%");
});
});
}
}
}