PHP code example of laravelutilities / repository

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

    

laravelutilities / repository example snippets


$this->repository->findByFieldFromCache('created_at', 'somevalue'); // extending cache repository; fetch only single value
$this->repository->findByFieldsFromCache(['created_at' => 'somevalue', 'city' => 'someanothervalue',...]); // fetch multiple values
$this->repository->findByField('created_at', 'somevalue'); // extending model repository; fetch only single value
$this->repository->findByField('created_at', 'somevalue'); // extending model repository; fetch only single value

public function fetchByFieldFromCache($key, $value);
public function fetchByFieldsFromCache(array $fieldsAndValues);

public function getById($id);
public function getByIds(array $ids)



use App\Repositories\OrganizationRepository;

protected $organization;
    
public function __construct()
{
    $this->organization = new OrganizationRepository();
}


namespace App\Repositories;

use App\Models\AppLog;
use LaravelUtility\Repository\Repositories\ModelRepository;

class AppLogRepository extends ModelRepository
{
    public function __construct()
    {
        parent::__construct(new AppLog());
    }
}



namespace App\Repositories;

use App\Models\AppLog;
use LaravelUtility\Repository\Repositories\CacheRepository;

class AppLogRepository extends CacheRepository
{
    public function __construct()
    {
        parent::__construct(new AppLog());
    }
}


public function findByField($key, $value);
public function findByFields(array $fieldsAndValues);

public function fetchByField($key, $value);
public function fetchByFields(array $fieldsAndValues);

public function findByFieldFromCache($key, $value);
public function findByFieldsFromCache(array $fieldsAndValues);

public function fetchByFieldFromCache($key, $value);
public function fetchByFieldsFromCache(array $fieldsAndValues);

public function getById($id);
public function getByIds(array $ids)


$this->repository->findByCreatedAt('somevalue'); // extending model repository; fetch only single value

$this->repository->findByCreatedAt('somevalue','cache'); // extending cache repository; fetch only single value

$this->repository->fetchByCreatedAt(['created_at' => 'somevalue', 'city' => 'someanothervalue',...]); // fetch multiple values
bash
php artisan vendor:publish --tag=repository
bash
php artisan make:repository <name> --model=<model> --cache=true/false