PHP code example of fernandozueet / laravel-doctrine-repository

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

    

fernandozueet / laravel-doctrine-repository example snippets


Ldr\Core\DoctrineRepositoryServiceProvider::class,



/**
 * User entity repository. 
 *
 * Code generated by cli command.
 *
 * @see http://github.com/fernandozueet/laravel-doctrine-repository
 *
 * @copyright 2018
 */

namespace App\Repositories\User;

use Ldr\Src\DoctrineBaseRepository;

class UserDocRepository extends DoctrineBaseRepository implements UserRepositoryInterface
{
    /**
     * Construct.
     */
    public function __construct()
    {
        parent::__construct();
        $this->main($this->fkEntities, $this->mAlias, __CLASS__);
    }

    /*-------------------------------------------------------------------------------------
    * CONFIGS
    *-------------------------------------------------------------------------------------*/

    /**
     * Foreign key entities names.
     *
     * @var array
     */
    private $fkEntities = ['UserGenre'];

    /**
     * Main alias.
     *
     * @var string
     */
    private $mAlias = 'u';

    /*-------------------------------------------------------------------------------------
    * GENERAL
    *-------------------------------------------------------------------------------------*/

    /**
     * Method of insertion in the database.
     * Returns the created object.
     *
     * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
     *
     * @return object
     */
    public function create(array $params): object
    {
        //$this->setReturn('doctrine'); //optional - default: array
        return $this->setCreateArray([
            'fieldTest1',
            'fieldTest2:fk=classNameFk', //foreign key
        ], $params);
    }

    /**
     * Method to update. To update more than one data, use the method updateQuery.
     * Returns the created object.
     *
     * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
     * @param int   $id     table id
     *
     * @return object
     */
    public function update(array $params, int $id): object
    {
        //$this->setReturn('doctrine'); //optional - default: array
        return $this->setUpdateArray([
            'fieldTest1',
            'fieldTest2:fk=classNameFk', //foreign key
        ], $params, $id);
    }

    /**
     * Method to update.
     * Returns total of records affected.
     *
     * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
     *
     * @return int
     */
    public function updateQuery(array $params): int
    {
        return $this->mainUpdateQuery(function () use ($params) {
            $this->setUpdateArrayQuery([
                'fieldTest1',
                'fieldTest2',
            ], $params);
        });
    }

    /*-------------------------------------------------------------------------------------
    * SELECTS
    *-------------------------------------------------------------------------------------*/

    /**
     * Settings select.
     * All the data from the table.
     */
    public function selectAll()
    {
        //select
        $this->select("ug, {$this->mAlias}");
        $this->from();

        //joins
        $this->innerJoinUserGenre();               

        //set results (optional) - more information see the documentation.
        //$this->setQueryResultFormat('getResult'); 

        //set hidration (optional) - more information see the documentation.
        //$this->addHydrateObject(); 
        //$this->addCustomHydrationMode('ObjectAndScalarHydrator');

        //$this->setReturn('doctrine'); //optional - default: array
    }

    /*-------------------------------------------------------------------------------------
    * JOINS
    *-------------------------------------------------------------------------------------*/
        
    /**
     * Inner join UserGenre.
     */
    private function innerJoinUserGenre()
    {
        $this->innerJoin("{$this->mAlias}.userGenre", 'ug');
    }
    
    /*-------------------------------------------------------------------------------------
    * WHERES
    *-------------------------------------------------------------------------------------*/

    /**
     * Where field u.id = ?
     *
     * @param int $value
     */
    public function whereIdEq(int $value)
    {
        return $this->expr('id', '=', $value);
    }

    /*-------------------------------------------------------------------------------------
    * ORDERS BYS
    *-------------------------------------------------------------------------------------*/

    /**
     * Sort by field u.id
     *
     * @param string $value DESC | ASC
     */
    public function orderId(string $value = 'DESC')
    {
        $this->addOrderBy('id', $value);
    }

    /*-------------------------------------------------------------------------------------
    * GROUPS BYS
    *-------------------------------------------------------------------------------------*/

    /**
     * Group by field u.id
     */
    public function groupById()
    {
        $this->addGroupBy('id');
    }

    /*-------------------------------------------------------------------------------------
    * HAVINGS
    *-------------------------------------------------------------------------------------*/

    /**
     * Having field u.id = ?
     *
     * @param int $value
     */
    public function havingIdEq(int $value)
    {
        return $this->expr('id', '=', $value);
    }

    /*-------------------------------------------------------------------------------------
    * DQL
    *-------------------------------------------------------------------------------------*/

    //Dql methods here
    //
}



/**
 * User repository interface.
 *
 * Code generated by cli command.
 *
 * @see http://github.com/fernandozueet/laravel-doctrine-repository
 *
 * @copyright 2018
 */

namespace App\Repositories\User;

interface UserRepositoryInterface
{
    /*-------------------------------------------------------------------------------------
    * OTHERS
    *-------------------------------------------------------------------------------------*/

    //Others here
    //

    public function whereIdEq(int $value);

    public function orderId(string $value = 'DESC');

    public function groupById();

    public function havingIdEq(int $value);

    /*-------------------------------------------------------------------------------------
    * GENERAL
    *-------------------------------------------------------------------------------------*/

    public function create(array $params): object;

    public function update(array $params, int $id): object;

    public function updateQuery(array $params): int;

    public function selectAll();

    public function setTransaction($conn);

    public function beginTransaction();

    public function commitTransaction();

    public function rollBackTransaction();

    public function find(int $id, string $typeTreat = '', array $treatObject = []): object;

    public function createQuery();

    public function setQuery($query);

    public function getQuery();

    public function readQuery(string $typeTreat = '', array $treatObject = []): object;

    public function paginator(int $firstResult, int $limit);

    public function setMaxResults(int $limit);

    public function orderByRand();

    public function setWhere($param);

    public function setAndWhere($param);

    public function setOrWhere($param);

    public function setCondOrWhere();

    public function setCondAndWhere();

    public function setCondNotWhere();

    public function setParentStartWhere();

    public function setParentEndWhere();

    public function whereExpr($function);

    public function setHaving($param);

    public function setAndHaving($param);

    public function setOrHaving($param);

    public function setCondOrHaving();

    public function setCondAndHaving();

    public function setCondNotHaving();

    public function setParentStartHaving();

    public function setParentEndHaving();

    public function havingExpr($function);

    public function deleteQuery(): bool;
}



namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class UserDocRepositoryServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('\App\Repositories\User\UserRepositoryInterface', function ($app) {
            return new \App\Repositories\User\UserDocRepository();
        });
    }
}


'managers' => [
    'default' => [ 
        //.....
    ],
    'otherConnection' => [ 
        //-----------------------------------------------
        //Laravel doctrine repository config
        //-----------------------------------------------
        'LdrConfig' => [
            'namespaceEntities' => 'App\Entities',
        ],
        //-----------------------------------------------
        'dev' => env('APP_DEBUG', false),
        'meta' => env('DOCTRINE_METADATA', 'annotations'),
        'connection' => env('DB_CONNECTION', 'mysql'),
        'namespaces' => [],
        'paths' => [
            base_path('app\Entities'),
        ],

        'repository' => Doctrine\ORM\EntityRepository::class,
        'proxies' => [
            'namespace' => false,
            'path' => storage_path('proxies'),
            'auto_generate' => env('DOCTRINE_PROXY_AUTOGENERATE', true),
        ],
        /*
        |--------------------------------------------------------------------------
        | Doctrine events
        |--------------------------------------------------------------------------
        |
        | The listener array expects the key to be a Doctrine event
        | e.g. Doctrine\ORM\Events::onFlush
        |
        */
        'events' => [
            'listeners' => [],
            'subscribers' => [],
        ],
        'filters' => [],
        /*
        |--------------------------------------------------------------------------
        | Doctrine mapping types
        |--------------------------------------------------------------------------
        |
        | Link a Database Type to a Local Doctrine Type
        |
        | Using 'enum' => 'string' is the same of:
        | $doctrineManager->extendAll(function (\Doctrine\ORM\Configuration $configuration,
        |         \Doctrine\DBAL\Connection $connection,
        |         \Doctrine\Common\EventManager $eventManager) {
        |     $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
        | });
        |
        | References:
        | http://doctrine-orm.readthedocs.org/en/latest/cookbook/custom-mapping-types.html
        | http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types
        | http://doctrine-orm.readthedocs.org/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html
        | http://doctrine-orm.readthedocs.org/en/latest/reference/basic-mapping.html#reference-mapping-types
        | http://symfony.com/doc/current/cookbook/doctrine/dbal.html#registering-custom-mapping-types-in-the-schematool
        |--------------------------------------------------------------------------
        */
        'mapping_types' => [
            //'enum' => 'string'
        ],
    ],
]

public function __construct()
{
    parent::__construct('otherConnection'); //set new connection here
    $this->main($this->fkEntities, $this->mAlias, __CLASS__);
}
 
$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

/**
 * User repository
 *
 * @var \App\Repositories\User\UserRepositoryInterface
 */
private $userRepository;

/**
 * Construct.
 *
 * @return void
 */
public function __construct(\App\Repositories\User\UserRepositoryInterface $userRepository)
{
    $this->userRepository = $userRepository;
}
 
$userRepository = app('\App\Repositories\User\UserDocRepository');
//or
$userRepository = new \App\Repositories\User\UserDocRepository();

/**
 * User repository
 *
 * @var \App\Repositories\User\UserDocRepository
 */
private $userRepository;

/**
 * Construct.
 *
 * @return void
 */
public function __construct()
{
    $this->userRepository = app('\App\Repositories\User\UserDocRepository');
    //or
    $this->userRepository = new \App\Repositories\User\UserDocRepository();
}

/**
 * Method of insertion in the database.
 * Returns the created object.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 *
 * @return object
 */
public function create(array $params): object
{
    //$this->setReturn('doctrine'); //optional - default: array
    return $this->setCreateArray([
        'firstName',
        'lastName',
        'userGenre:fk=UserGenre', //foreign key
    ], $params);
}

/**
 * Method of insertion in the database.
 * Returns the created object.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 *
 * @return object
 */
public function create(array $params): object
{
    //$this->setReturn('doctrine'); //optional - default: array
    return $this->setCreateArray([
        'firstName',
        'lastName',
        'userGenre:fk=UserGenre', //foreign key
    ], $params, false);
}

/**
 * Method of insertion in the database.
 * Returns the created object.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 *
 * @return object
 */
public function create(array $params): object
{
    //$this->setReturn('doctrine'); //optional - default: array

    //Ex 1: The return object will return only the firstName and lastName fields
    return $this->setCreateArray([
        'firstName',
        'lastName',
        'userGenre:fk=UserGenre', //foreign key
    ], $params, true, '

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //insert
    $res = $userRepository->create([
        'firstName' => 'Alex',
        'lastName' => 'Silva', 
        'userGenre' => 1
    ]);

    //Returns the object.
    var_dump($res);

} catch (\Exception $e) {

    //error
    return $e->getMessage();
}

/**
 * Method to update. To update more than one data, use the method updateQuery.
 * Returns the object.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 * @param int   $id     table id
 *
 * @return object
 */
public function update(array $params, int $id): object
{
    //$this->setReturn('doctrine'); //optional - default: array
    return $this->setUpdateArray([
        'firstName',
        'lastName',
        'userGenre:fk=UserGenre', //foreign key
    ], $params, $id);
}

/**
 * Method to update. To update more than one data, use the method updateQuery.
 * Returns the object.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 * @param int   $id     table id
 *
 * @return object
 */
public function update(array $params, int $id): object
{
    //$this->setReturn('doctrine'); //optional - default: array
    return $this->setUpdateArray([
        'firstName',
        'lastName',
        'userGenre:fk=UserGenre', //foreign key
    ], $params, $id, false);
}

/**
 * Method to update. To update more than one data, use the method updateQuery.
 * Returns the object.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 * @param int   $id     table id
 *
 * @return object
 */
public function update(array $params, int $id): object
{
    //$this->setReturn('doctrine'); //optional - default: array

    //Ex 1: The return object will return only the firstName and lastName fields
    return $this->setUpdateArray([
        'firstName',
        'lastName',
        'userGenre:fk=UserGenre', //foreign key
    ], $params, $id, true, '

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //update
    $res = $userRepository->update([
        'firstName' => 'Alex 2',
        'lastName' => 'Silva 2', 
        'userGenre' => 2
    ], 1);

    //Returns the object
    var_dump($res);

} catch (\Exception $e) {

    //error
    return $e->getMessage();
}

/**
 * Method to update.
 * Returns total of records affected.
 *
 * @param array $params Use the same naming convention as the database attribute. In camel case. Ex: firstName
 *
 * @return int
 */
public function updateQuery(array $params): int
{
    return $this->mainUpdateQuery(function () use ($params) {

        //set individual
        $this->set('firstName', $params['firstName']);
        
        //set json mysql
        $this->setJsonReplace('name', 'firstName', $params['firstName']);
        $this->setJsonSet('name', 'firstName', $params['firstName']);
        $this->setJsonInsert('name', 'firstName', $params['firstName']);

        //set all array
        $this->setUpdateArrayQuery([
            'firstName',
            'lastName',
            'userGenre',
        ], $params);

        //Do not automatically update updatedAt
        $this->setUpdateArrayQuery([
            'firstName',
            'lastName',
            'userGenre',
        ], $params, false);
    });
}

/*-------------------------------------------------------------------------------------
* WHERES
*-------------------------------------------------------------------------------------*/

/**
 * Where field u.id = ?
 *
 * @param int $value
 */
public function whereIdEq(int $value)
{
    return $this->expr('id', '=', $value);
}

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //start query
    $userRepository->createQuery();

    //where
    $userRepository->whereExpr(function () use ($userRepository) {

        //where id = 17
        $userRepository->setWhere($userRepository->whereIdEq(17));

        //add more conditions here
        //
    });

    //update
    $res = $userRepository->updateQuery([
        'firstName' => 'Alex 2',
        'lastName' => 'Silva 2', 
        'userGenre' => 2
    ], 1);

    //total of records affected
    var_dump($res);

} catch (\Exception $e) {

    //error
    return $e->getMessage();
}

/*-------------------------------------------------------------------------------------
* WHERES
*-------------------------------------------------------------------------------------*/

/**
 * Where field u.id = ?
 *
 * @param int $value
 */
public function whereIdEq(int $value)
{
    return $this->expr('id', '=', $value);
}

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //start query
    $userRepository->createQuery();

    //where
    $userRepository->whereExpr(function () use ($userRepository) {

        //where id = 17
        $userRepository->setWhere($userRepository->whereIdEq(17));

        //add more conditions here
        //
    });

    //delete
    $res = $userRepository->deleteQuery();

    //returned boolean 
    var_dump($res);

} catch (\Exception $e) {

    //error
    return $e->getMessage();
}

/*-------------------------------------------------------------------------------------
* CONFIGS
*-------------------------------------------------------------------------------------*/

/**
 * Foreign key entities names.
 *
 * @var array
 */
private $fkEntities = ['UserGenre'];

/**
 * Main alias.
 *
 * @var string
    */
private $mAlias = 'u';

/*-------------------------------------------------------------------------------------
* SELECTS
*-------------------------------------------------------------------------------------*/

/**
 * Settings select.
 * All the data from the table.
 */
public function selectAll()
{
    //select
    $this->select("ug, {$this->mAlias}"); //brings all the data
    //$this->select("{$this->mAlias}.id, {$this->mAlias}.firsName, {$this->mAlias}.lastName, ug.id, ug.desc"); //brings specific data
    //$this->select("{$this->mAlias}, PARTIAL ug.{id, desc}"); //add result getArrayResult
    //$this->addSelect("ug"); //add select several lines
    $this->from();

    //joins
    $this->innerJoinUserGenre();               

    //set results (optional) 
    //$this->setQueryResultFormat('getResult'); 
    //$this->setQueryResultFormat('getArrayResult'); 
    //$this->setQueryResultFormat('getSingleResult'); 
    //$this->setQueryResultFormat('getOneOrNullResult'); 
    //$this->setQueryResultFormat('getScalarResult'); 
    //$this->setQueryResultFormat('getSingleScalarResult'); 

    //set hidration (optional) 
    //$this->addHydrateObject(); 
    //$this->addHydrateArray(); 
    //$this->addHydrateScalar(); 
    //$this->addHydrateSingleScalar(); 
    //$this->addCustomHydrationMode('ObjectAndScalarHydrator');
    //$this->addCustomHydrationMode('ArrayHydratorCustom');

    //$this->setReturn('doctrine'); //optional - default: array
}

/*-------------------------------------------------------------------------------------
* JOINS
*-------------------------------------------------------------------------------------*/
    
/**
 * Inner join UserLocate.
 */
private function innerJoinUserGenre()
{
    $this->innerJoin("{$this->mAlias}.userGenre", 'ug');
    //or 
    //$this->innerJoin('UserGenre', 'ug', 'WITH', "ug.id = {$this->mAlias}.userGenre"); 
}

/**
 * Left join UserLocate.
 */
private function leftJoinUserGenre()
{
    $this->leftJoin("{$this->mAlias}.userGenre", 'ug');
    //or 
    //$this->leftJoin('UserGenre', 'ug', 'WITH', "ug.id = {$this->mAlias}.userGenre"); 
}

/**
 * Join UserLocate.
 */
private function joinUserGenre()
{
    $this->join("{$this->mAlias}.userGenre", 'ug');
    //or 
    //$this->join('UserGenre', 'ug', 'WITH', "ug.id = {$this->mAlias}.userGenre"); 
}

/*-------------------------------------------------------------------------------------
* WHERES
*-------------------------------------------------------------------------------------*/

/**
 * Where field u.id = ?
 *
 * @param int $value
 */
public function whereIdEq(int $value)
{
    return $this->expr('id', '=', $value);
}

/*-------------------------------------------------------------------------------------
* ORDERS BYS
*-------------------------------------------------------------------------------------*/

/**
 * Sort by field u.id
 *
 * @param string $value DESC | ASC
 */
public function orderId(string $value = 'DESC')
{
    $this->addOrderBy('id', $value);
}

/*-------------------------------------------------------------------------------------
* GROUPS BYS
*-------------------------------------------------------------------------------------*/

/**
 * Group by field u.id
 */
public function groupById()
{
    $this->addGroupBy('id');
}

/*-------------------------------------------------------------------------------------
* HAVINGS
*-------------------------------------------------------------------------------------*/

/**
 * Having field u.id = ?
 *
 * @param int $value
 */
public function havingIdEq(int $value)
{
    return $this->expr('id', '=', $value);
}

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //start query
    $userRepository->createQuery();

    //settings select
    $userRepository->selectAll();

    //where (optional)
    $userRepository->whereExpr(function () use ($userRepository) {

        //where id = 17
        $userRepository->setWhere($userRepository->whereIdEq(17));

        //where functions
        //$userRepository->setAndWhere($userRepository->whereFirstNameEq('Alex')); // AND firstName = 'alex'
        //$userRepository->setOrWhere($userRepository->whereFirstNameEq('Alex')); // OR firstName = 'alex'
        //$userRepository->setCondAndWhere(); // AND
        //$userRepository->setCondOrWhere(); // OR
        //$userRepository->setCondNotWhere(); // NOT
        //$userRepository->setParentStartWhere(); // (
        //$userRepository->setParentEndWhere(); // )

        //add more conditions here
        //
    });

    //having (optional)
    $userRepository->havingExpr(function () use ($userRepository) {

        //having id = 17
        $userRepository->setHaving($userRepository->havingIdEq(17));

        //where functions
        //$userRepository->setAndHaving($userRepository->havingFirstNameEq('Alex')); // AND firstName = 'alex'
        //$userRepository->setOrHaving($userRepository->havingFirstNameEq('Alex')); // OR firstName = 'alex'
        //$userRepository->setCondAndHaving(); // AND
        //$userRepository->setCondOrHaving(); // OR
        //$userRepository->setCondOrHaving(); // NOT
        //$userRepository->setParentStartHaving(); // (
        //$userRepository->setParentEndHaving(); // )

        //add more conditions here
        //
    });

    //order by (optional)
    $userRepository->orderId('ASC');

    //order by rand (optional)
    $userRepository->orderByRand();

    //group by (optional)
    $userRepository->groupById();

    //max results (optional)
    $userRepository->setMaxResults(1);

    //paginator (optional)
    $userRepository->paginator(0, 1);

    //results - original result
    $res = $userRepository->readQuery();

    //results - will return only the firstName and lastName fields. 
    //Works only when all data is returned and no setQueryResultFormat is set.
    $res = $userRepository->readQuery('

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //find 
    $res = $userRepository->find(36);

    //or

    //find - will return only the firstName and lastName fields. 
    $res = $userRepository->find(36, 'eturn $e->getMessage();
}

$userGenre = app('\App\Repositories\UserGenre\UserGenreRepositoryInterface');
$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

//init transaction
$transaction = $userGenre->beginTransaction();

//-----------------------
//insert userGenre
try {

    //set transaction
    $userGenre->setTransaction($transaction);
    
    //insert
    $res = $userGenre->create([
        'desc' => 'woman'
    ]);

} catch (\Exception $e) {

    //rollBack
    $userGenre->rollBackTransaction();

    //error
    return $e->getMessage();
}

//-----------------------
//insert user
try {

    //setTransaction
    $userRepository->setTransaction($transaction);

    //insert
    $res = $userRepository->create([
        'firstName' => 'Alex',
        'lastName' => 'Silva', 
        'userGenre' => $res->id
    ]);

} catch (\Exception $e) {

    //rollBack
    $userRepository->rollBackTransaction($transaction);

    //error
    return $e->getMessage();
}

//commit data
$userGenre->commitTransaction();

/*-------------------------------------------------------------------------------------
* DQL
*-------------------------------------------------------------------------------------*/

/**
 * Select with dql.
 *
 * @param array $params
 * @return object
 */
public function selectDql(array $params): object
{
    $this->createQueryDql("SELECT u FROM {$this->entityMain} AS u WHERE u.id = ?0"); //dql query
    $this->setParameterDql(0, $params['id']); //set parameter
    $this->paginatorDql($params['firstResult'], $params['maxResults']); //paginator

    //$this->setReturn('doctrine'); //optional - default: array

    //result
    return $this->getResultDql(); 

    //or

    //result - will return only the firstName and lastName fields. 
    return $this->getResultDql('

$userRepository = app('\App\Repositories\User\UserRepositoryInterface');

try {

    //dql select
    $res = $userRepository->selectDql([
        'id' => 1,
        'firstResult' => 0, 
        'maxResults' => 5
    ]);

    //returned results 
    var_dump($res);

} catch (\Exception $e) {

    //error
    return $e->getMessage();
}

/**
 * Where field u.id = ?
 *
 * @param int $id
 */
public function whereIdEq(int $id)
{
    return $this->expr('id', '=', $id);
}

/**
 * Where field json u.name.firstname LIKE ?
 *
 * @param string $value
 */
public function whereNameFirstNameLike(string $value)
{
    return $this->expr($this->fieldJson('name', 'firstName'), 'LIKE', "%$value%", false);
}

/**
 * Where field ug.id = ?
 *
 * @param int $id
 */
public function whereUserGenreIdEq(int $id)
{
    return $this->expr('ug.id', '=', $id, false);
}

/**
 * Where field u.id > ?
 *
 * @param int $id
 */
public function whereIdGt(int $id)
{
    return $this->expr('id', '>', $id);
}

/**
 * Where field u.id >= ?
 *
 * @param int $id
 */
public function whereIdGte(int $id)
{
    return $this->expr('id', '>=', $id);
}

/**
 * Where field u.id < ?
 *
 * @param int $id
 */
public function whereIdLt(int $id)
{
    return $this->expr('id', '<', $id);
}

/**
 * Where field u.id <= ?
 *
 * @param int $id
 */
public function whereIdLte(int $id)
{
    return $this->expr('id', '<=', $id);
}

/**
 * Where field u.id <> ?
 *
 * @param int $id
 */
public function whereIdNeq(int $id)
{
    return $this->expr('id', '<>', $id);
}

/**
 * Where field u.id IS NULL
 */
public function whereIdIsNull()
{
    return $this->expr('id', 'IS NULL', '');
}

/**
 * Where field u.id IS NOT NULL
 */
public function whereIdIsNotNull()
{
    return $this->expr('id', 'IS NOT NULL', '');
}

/**
 * Where field u.id * ?
 *
 * @param int $id
 */
public function whereIdProd(int $id)
{
    return $this->expr('id', '*', $id);
}

/**
 * Where field u.id - ?
 *
 * @param int $id
 */
public function whereIdDiff(int $id)
{
    return $this->expr('id', '-', $id);
}

/**
 * Where field u.id + ?
 *
 * @param int $id
 */
public function whereIdSum(int $id)
{
    return $this->expr('id', '+', $id);
}

/**
 * Where field u.id / ?
 *
 * @param int $id
 */
public function whereIdQuot(int $id)
{
    return $this->expr('id', '/', $id);
}

/**
 * Where field u.id IN (?,?,?,...)
 *
 * @param array $values
 */
public function whereIdIn(array $values)
{
    return $this->expr('id', 'IN', $values);
}

/**
 * Where field u.id NOT IN (?,?,?,...)
 *
 * @param array $values
 */
public function whereIdNotIn(array $values)
{
    return $this->expr('id', 'NOT IN', $values);
}

/**
 * Where field u.firstName LIKE ?
 *
 * @param string $value
 */
public function whereFirstNameLike(string $value)
{
    return $this->expr('firstName', 'LIKE', "%$value%");
}

/**
 * Where field u.firstName NOT LIKE ?
 *
 * @param string $value
 */
public function whereFirstNameNotLike(string $value)
{
    return $this->expr('firstName', 'NOT LIKE', "%$value%");
}

/**
 * Where field u.createdAt BETWEEN ? AND ?
 *
 * @param string $value1
 * @param string $value2
 * @return void
 */
public function whereCreatedAtBetween(string $value1, string $value2)
{
    return $this->expr('createdAt', '', $this->exprBetween($value1, $value2), true, false);
}

/**
 * Where field u.createdAt NOT BETWEEN ? AND ?
 *
 * @param string $value1
 * @param string $value2
 * @return void
 */
public function whereCreatedAtNotBetween(string $value1, string $value2)
{
    return $this->expr('createdAt', 'NOT', $this->exprBetween($value1, $value2), true, false);
}

/**
 * Sort by field u.id
 *
 * @param string $value DESC | ASC
 */
public function orderId(string $value = 'DESC')
{
    $this->addOrderBy('id', $value);
}

/**
 * Sort by field ug.id
 *
 * @param string $value DESC | ASC
 */
public function orderUserGenreId(string $value = 'DESC')
{
    $this->addOrderBy('ug.id', $value, false);
}

/**
 * Group by field u.id
 */
public function groupById()
{
    $this->addGroupBy('id');
}

/**
 * Group by field ug.id
 */
public function groupByUserGenreId()
{
    $this->addGroupBy('ug.id', false);
}

//principal entity namespace (string)
var_dump($this->entityMain);

//namespaces of entities (array)
var_dump($this->ent);

//principal entity name (string)
var_dump($this->mainNameEntity);

//search entity (string)
var_dump($this->searchEnt('UserGenre'));

//get reference
$this->getReference("UserGenre", $id);

//persist
$this->persist($entity);

//flush
$this->flush();

//clear
$this->clear();

//json extract mysql - name.firstName
$this->fieldJson('name', 'firstName');

//created name parameter.
//will pass the die to bind :dc_value1
$this->createNamedParameter($params['firstName']);
bash
php artisan vendor:publish --tag="configRepository"
bash
php artisan make:doctrine-repository:entities
bash
php artisan make:doctrine-repository User
bash
php artisan make:doctrine-repository SubPath/User