PHP code example of pradeepdev001 / laravel-smart-filter
1. Go to this page and download the library: Download pradeepdev001/laravel-smart-filter 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/ */
pradeepdev001 / laravel-smart-filter example snippets
class User extends Model
{
use Filterable;
protected array $filterable = ['name', 'email', 'status'];
public function posts(): HasMany
{
return $this->hasMany(Post::class);
}
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}
}
use Pradeepdev\SmartFilter\Facades\SmartFilter;
use Pradeepdev\SmartFilter\Contracts\OperatorContract;
use Pradeepdev\SmartFilter\DTOs\FilterInput;
use Illuminate\Database\Eloquent\Builder;
class StartsWithOperator implements OperatorContract
{
public function apply(Builder $builder, FilterInput $input): Builder
{
return $builder->where($input->field, 'LIKE', $input->value . '%');
}
public function handles(): array
{
return ['starts_with'];
}
}
// In AppServiceProvider::boot()
SmartFilter::extend(new StartsWithOperator());