PHP code example of jeidison / model-filtrable

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

    

jeidison / model-filtrable example snippets


...

use Jeidison\Filtrable\Filtrable;

class Professional extends Model
{
    use Filtrable;

    ...
    protected $fillable = [
        //All fields filtrable;
    ];
    ...

    public function places()
    {
        return $this->belongsToMany(Place::class, 'prof_place', 'id_prof', 'id_place');
    }
    
    public function specialties()
    {
        return $this->belongsToMany(Specialty::class, 'prof_spec', 'id_prof', 'id_spec');
    }
}

...

use App\Models\Professional;

class ProfessionalService implements IProfessionalService
{
    public function filter()
    {
         return Professional::filter(request()->all())->get(); 
        // or
         return Professional::filter(['field_one' => 'value1'])->get();     
    }
}

    /api/professionals?id_prof:between=1,2
    /api/professionals?updated_at:between=2020-03-10 14:00:27,2020-03-10 14:00:27

    /api/professionals?id_prof:notBetween=1,2
    /api/professionals?updated_at:notBetween=2020-03-10 14:00:27,2020-03-10 14:00:27

    /api/professionals?created_at:whereDate=2020-03-10

    /api/professionals?with=places,specialties

    /api/professionals?has=places

    /api/places->id_place=1
    /api/places->professionals->id_place=1
    /api/places->professionals->id_place:<>=1
    /api/places->professionals->id_place:<=1
    ...