PHP code example of saritasa / laravel-repositories

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

    

saritasa / laravel-repositories example snippets


return [
	'bindings' => [
	    \App\Models\User::class => \App\Repositories\UserRepository::class,
	],
];

    $repositoryFactory = app(\Saritasa\LaravelRepositories\Repositories\IRepositoryFactory::class);
    $userRepository = $repositoryFactory->getRepository(\App\Models\User::class);

    $criteria = [
        'field1' => 'value1',
        'field2' => 1,
    ];

    $criteria = [
        ['field1', '<>', 'value1'],
        ['field2', '>', 1, 'or'],
        ['field3', 'in', [1, 2]],
        ['field4', 'not in', new \Illuminate\Support\Collection([1, 2])],
    ];

    $criteria = [
            new Criterion([
                Criterion::OPERATOR => '<>',
                Criterion::VALUE => 'value1',
                Criterion::ATTRIBUTE => 'field1',
            ]),
            new Criterion([
                Criterion::OPERATOR => '>',
                Criterion::VALUE => 1,
                Criterion::ATTRIBUTE => 'field2',
                Criterion::BOOLEAN => 'or',
            ]),
            new Criterion([
                Criterion::OPERATOR => 'in',
                Criterion::VALUE => [1, 2],
                Criterion::ATTRIBUTE => 'field3',
            ]),   
            new Criterion([
                Criterion::OPERATOR => 'not in',
                Criterion::VALUE => [1, 2],
                Criterion::ATTRIBUTE => 'field4',
            ]),                     
    ];

    $criteria = [
        [
            ['field1', '<>', 'value1'],
            ['field2', '>', 1, 'or'],
        ],
        [
            ['field3', 'in', [1, 2]],
            ['field4', 'not in', [1, 2],
            'boolean' => 'or',
        ],
    ];

    $criteria = [
        new RelationCriterion('roles', [['slug', 'in', [1, 2]]], 'or'), 
    ];
  
$usersRepository->getWith(
    ['role', 'supervisors'],
    ['phones'],
    [],
    new Saritasa\LaravelRepositories\DTO\SortOptions('name', 'DESC')
);
 vendor/bin/phpcs
 vendor/bin/phpcbf
 vendor/bin/phpunit
bash
php artisan vendor:publish --tag=laravel_repositories