PHP code example of letkode / entity-traits-bundle

1. Go to this page and download the library: Download letkode/entity-traits-bundle 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/ */

    

letkode / entity-traits-bundle example snippets


// config/bundles.php
return [
    Letkode\EntityTraitsBundle\LetkodeEntityTraitsBundle::class => ['all' => true],
];

use Letkode\EntityTraitsBundle\Trait\Entity\UuidTrait;

#[ORM\Entity]
class Product
{
    use UuidTrait;
}

$entity->setTranslation('es', 'name', 'Producto');
$entity->getTranslation('es', 'name'); // 'Producto'

$entity->setParameter('color', 'red');
$entity->getParameter('color'); // 'red'
$entity->setParameters(['size' => 'L'], force: false); // recursive merge

$repo->save($entity);
$repo->remove($entity);
$repo->findByUuid($uuid);           // returns T|null
$repo->findOrFailByUuid($uuid);     // throws EntityNotFoundException
$repo->paginate($qb, $tableQuery, sortable: ['name'], searchable: ['name', 'email']);

$this->addTranslatedOrderBy($qb, 'p', 'name', $locale, 'ASC');
$this->addTranslatedSearch($qb, 'p', 'name', $searchTerm, $locale);

$query = TableQueryRequest::fromArray($request->query->all());
// $query->page, $query->perPage, $query->q, $query->sort, $query->dir

// Returned by BaseRepositoryTrait::paginate()
$result->data;       // array of entities
$result->total;      // int
$result->page;       // int
$result->perPage;    // int
$result->totalPages; // int (computed)

$email = new Email('  [email protected]  '); // '[email protected]'
$slug  = new Slug('My Product Name');        // 'my-product-name'