1. Go to this page and download the library: Download ulex/epic-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/ */
UserEloquentRepository created successfully.
UserEloquentInterface created successfully.
UserEloquentCachingDecorator created successfully.
# Example when injecting to a controller
use App\Repositories\Interfaces\UserEloquentInterface;
public function __construct(UserEloquentInterface $userRepository)
{
$this->userRepository = $userRepository;
}
...
public function find($id)
{
//retrieve from db and then cache the result
$user = $this->userRepository->find($id);
//retrieve straight from source, uncached
$user = $this->userRepository->fromSource()->find($id);
}
protected function remember(string $function, $arguments, bool $isCollection = false)
public function getLatestPost($user_id)
{
return $this->remember(__FUNCTION__, func_get_args());
}
public function flushGetKeys($model, $attributes = null)
{
$this->flushFunction('getLatestPost', ['user_id' => $model->user_id]);
parent::flushGetKeys($model, $attributes);
}
public function getLatestPost($user_id)
{
return $this->model->query()->where('user_id', '=', $user_id)->latest()->first();
}
public function getUserPosts($user_id)
{
return $this->remember(__FUNCTION__, func_get_args(), true);
}