PHP code example of michaelnabil230 / laravel-query-conditions

1. Go to this page and download the library: Download michaelnabil230/laravel-query-conditions 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/ */

    

michaelnabil230 / laravel-query-conditions example snippets


use Illuminate\Database\Eloquent\Model;
use MichaelNabil230\QueryConditions\Support\Condition;
use MichaelNabil230\QueryConditions\Concerns\HasQueryCondonation;
use MichaelNabil230\QueryConditions\Interfaces\QueryCondonation as InterfacesQueryCondonation;
use Illuminate\Database\Eloquent\Builder;

class YourModel extends Model implements InterfacesQueryCondonation
{
    use HasQueryCondonation;

    public function parseQBRule(Builder $query, Condition $condition, string $method): void
    {
        if ($condition->rule === 'age') {
            $query->{$method}('age', $condition->operator, $condition->value);
        }

        if ($condition->rule === 'created_at') {
            $query->{$method}('created_at', $condition->operator, $condition->value);
        }
    }
}

    $condonations = [
        Text::make('Name'),
        Number::make('Age')->min(1)->max(1000),
        Select::make('Job title', 'job_title')->options([
            'R' => 'Regional Manager',
            'A' => 'Assistant to the Regional Manager',
            'S' => 'Sales Associate',
        ])
    ];

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use MichaelNabil230\QueryConditions\QueryConditions;
use App\Models\User;

class ConditionController extends Controller
{
    public function getDataFromQueryConditions(Request $request)
    {
        $users = QueryConditions::for(User::class, $request->input('query'))
            ->get();

        return [
            'users' => $users,
        ];
    }
}