koutech/class-base-filter

Top layer for spatie-query-builder with class base filter and other featuer too.

v1.0 2020-06-04 14:27 UTC

This package is auto-updated.

Last update: 2025-06-23 00:54:19 UTC


README

composer require koutech/class-base-filter

Class Base Filter

  • Go to the app folder and create a folder name called Filter
  • Create Some class e.g UserFilter.php

Inside Filter Class

all you have to do is just extend the Koutech\TopLayerForSpatieQueryBuilder\Filter contain at least two methods fields and model inside class

<?php 

namespace App\Filter;

use Koutech\TopLayerForSpatieQueryBuilder\Filter;

use App\User;


class UserFilter extends Filter
{

    public function model() 
    {
        return User::class;
    }
    
    public function fields() 
    {
        return ['name'];
    }


}

Usage

<?php

$users = UserFilter::filter()->get();

Set Eager Loading

contain method called include inside class example if you want to contain post that belongs to the user all you have to do is...

<?php 

public function eagerLoading() 
{
    return ['post'];
}

Set Eager Loading From Url

contain method called include inside class example if you want to contain post that belongs to the user all you have to do is...

<?php 

public function includes() 
{
    return ['post'];
}