PHP code example of ralphschindler / basic-query-filter

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

    

ralphschindler / basic-query-filter example snippets


$parseTree = (new QueryFilter\Parser)->parse($filter);
foreach ($parseTree->getPredicates() as $predicateInfo) {
    list($combinedBy, $predicate) = $predicateInfo;
    // ...    
}

// $modelQuery is a Model::newQuery() instance (Illuminate\Database\Eloquent\Builder)

foreach ($parseTree->getPredicates() as $predicateInfo) {
    list($combinedBy, $predicate) = $predicateInfo;
    $op = ($predicate->op == '=~') ? 'like' : $predicate->op;
    if ($combinedBy === 'OR') {
        $modelQuery->orWhere((string)$predicate->left, $op, $predicate->right);
    } else {
        $modelQuery->where((string)$predicate->left, $op, $predicate->right);
    }
}