Skip to content

Cacheable

Gilberto Junior edited this page Dec 5, 2019 · 3 revisions

Avaliable for classes that extends CodeHappy\DataLayer\Repository.

Usage

Add the trait CodeHappy\DataLayer\Traits\Cacheable into the repository:

<?php

namespace App\Repositories;

use CodeHappy\DataLayer\Repository;
use CodeHappy\DataLayer\Traits\Cacheable;
use App\Repositories\CachingUserRepository;

class UserRepository extends Repository
{
    use Cacheable; // Add Trait

    protected $cachingRepository = CachingUserRepository::class; // Declare your Caching Repository class name
}

Method

To call the instance of CodeHappy\DataLayer\CachingRepository.

Syntax

public function cached(): CachingRepository;

Example

PHP's way:

$productRepository->cached()
    ->isEqualTo('store_id', 123456)
    ->isBetween('order_date', '2019-11-29 00:00:00', '2019-11-29 23:59:59')
    ->fetchFirst();

🡄 Debugable | Soft Deletes 🡆