PHP code example of saf / doctrine-orm-searchable-repository

1. Go to this page and download the library: Download saf/doctrine-orm-searchable-repository 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/ */

    

saf / doctrine-orm-searchable-repository example snippets


$filters = [
    'name'        => ['neq' => 'My name'],
    'author.name' => ['in' => ['Foo', 'Bar']],
    'rating'      => ['gte' => 4],
];

$orders = [
    'author.name' => 'ASC',
    'name'        => 'DESC',
];

$entities = $repository->search($filters, $orders);

$filters = [
    'name' => [
        'field'     => ['firstName', 'lastName],
        'condition' => 'like',
        'value'     => '%Lewis%',
    ],
];

$orders = [
    'author.name' => 'ASC',
    'name'        => 'DESC',
];

$entities = $repository->search($filters, $orders);


use SAF\SearchableRepository\SearchableRepository;

class MyRepository extends  SearchableRepository
{
    // ...
}

// add a new type handler to your search with the setType function
// the first parameter correspond to the doctrine type
// the second parameter is the filter type (that must implements \SAF\SearchableRepository\SearchableRepository\Types\TypeInterface interface)
$repository->setType('string', new MyStringFilterType());