PHP code example of naumov-adata / pipeline-filter

1. Go to this page and download the library: Download naumov-adata/pipeline-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/ */

    

naumov-adata / pipeline-filter example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use PipelineFilter\Core\Traits\HasPipelineFilter;

final class YourModel extends Model
{
    use HasPipelineFilter;

    // Другие методы и свойства модели
}



declare(strict_types=1);

namespace PipelineFilter\Core\Filters\Pipelines;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use PipelineFilter\Core\Filters\FilterPipelineInterface;

/**
 * Class ExampleFilter
 */
class ExampleFilter implements FilterPipelineInterface
{
    /**
     * @param Builder $builder
     * @param mixed $dto
     *
     * @return Builder
     */
    public static function apply(Builder $builder, mixed $dto): Builder
    {
        /** @var Model|Builder $builder */
        return true
            ? $builder->where('name', $dto->name)
            : $builder;
    }
}

$dto = new YourDataTransferObject(); // Создайте ваш DTO

$results = YourModel::pipelineFilter([
    AccessFilter::class,
    WithCompaniesFilter::class,
    FavoriteAccessFilter::class,
], $dto)->get();