PHP code example of logaretm / depo

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

    

logaretm / depo example snippets


class Task extends Model
{
    /**
     * @var array
     */
    protected $fillable = [
        'body',
        'completed'
    ];


    /**
     * @param $query
     * @return mixed
     */
    public function scopeCompleted ($query)
    {
        return $query->where('completed', true);
    }


    /**
     * @param $query
     * @return mixed
     */
    public function scopeInProgress ($query)
    {
        return $query->where('completed', false);
    }
}

$repository = new Repository(new Task);

$cachingRepository = new CachingRepository($repository, 10, app()['cache.store']);

$cachingRepository = new CachingRepository(new Task, 10, app()['cache.store']);

$completedTasks = $cachingRepository->where('completed', true)->get();

$completedTasks = $cachingRepository->completed()->get();

class TaskRepository extends Repository
{
    /**
     * Yep. that is it.
     *
     * @return mixed
     */
    function getRepositoryModel()
    {
        return Task::class;
    }
}
 

 $taskRepository = new TaskRepository;
 

  $taskRepository = new TaskRepository(new Task);
  

class CachingTaskRepository extends CachingRepositoryBase
{
    /**
     * Returns the primary cache key for this repository.
     *
     * @return mixed
     */
    public function getCacheTag()
    {
        return 'tasks';
    }

    /**
     * Returns the cache tags to be forgotten.
     *
     * @return mixed
     */
    public function getForgetTags()
    {
        return ['tasks'];
    }
}

$cachingRepository = new CachingTaskRepository($taskRepository, 10, app()['cache.store']);

$completedTasks = $cachingRepository->completed()->get();