PHP code example of patienceman / filtan

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

    

patienceman / filtan example snippets


namespace App\Http\QueryFilters;

use Patienceman\Filtan\QueryFilter;

class AirPlaneFilter extends QueryFilter {
    /**
     * Search specific values from Airplan by name
     *
     * @param string $query
     */
    public function query(string $query) {
        $this->builder->where('name', 'LIKE', '%' . $query . '%');
    }
}

namespace App\Http\QueryFilters\Model;

use Patienceman\Filtan\QueryFilter;

class AirPlaneFilter extends QueryFilter {
    /**
     * Search specific values from industry by name
     *
     * @param string $query
     */
    public function query(string $query) {
        $this->builder->where('name', 'LIKE', '%' . $query . '%');
    }
}

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Patienceman\Filtan\Filterable;

class Airplane extends Model {
    use HasFactory, Filterable;
}

namespace App\Http\Controllers\ApiControllers;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Services\Filters\CompanyFilter;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AirplaneController extends Controller {
    /**
     * Display a listing of the resource.
     *
     * @return JsonResponse
     */
    public function index(CompanyFilter $filter): JsonResponse {
        $planes = Airplane::filter($filter)->get();

        return response()->json([
            'data' => $planes,
            'message' => 'Airplanes retrieved successfully'
        ]);
    }
}
bash
php artisan filtan:config
filtan.php
bash
php artisan filtan:create {filter} --model={model}
bash
php artisan filtan:create AirPlaneFilter --model=AirPlane
bash
app/Http/QueryFilters/AirPlaneFilter.php
bash
php artisan filtan:create Model/AirPlaneFilter