PHP code example of slexx / comparisons-lang

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

    

slexx / comparisons-lang example snippets




lexx\CL\CL;
use Slexx\CL\Tokenizer;

$parser = new CL('>=18&<40', Tokenizer::T_INT);

var_dump($parser->compileToPHP('$age')); // "$age >= 18 && $age < 40"
var_dump($parser->compileToSQL('users', 'age')); // "`users`.`age` >= 18 AND `users`.`age` < 40"

'providers' => [
    // ...
    Slexx\CL\LaravelServiceProvider::class,
];

Users::CLFilter('age', '>=18&<40', 'int')->get();

$query = Users::query();

if (Request::has('birthday')) {
    $query->CLFilter('birthday', Request::get('birthday'), 'date');
}

if (Request::has('created_at')) {
    $query->CLFilter('created_at', Request::get('created_at'), 'date_time');
}

if (Request::has('rating')) {
    $query->CLFilter('rating', Request::get('rating'), 'int');
}

$users = $query->get();