PHP code example of mike-zange / laravel-entity-base-repositories

1. Go to this page and download the library: Download mike-zange/laravel-entity-base-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/ */

    

mike-zange / laravel-entity-base-repositories example snippets


    class UserController extends Controller
    {
        /**
         * @var UserRepository
         */
        private $userRepository;
    
        /**
         * Create a new controller instance.
         *
         * @param UserRepository $userRepository
         */
        public function __construct(UserRepository $userRepository)
        {
            $this->userRepository = $userRepository;
        }
        
        public function index(Request $request)
        {
            $users = $this->userRepository->all();
            return $users;
        }
    }
    

    namespace App\Repositories\Cache;
    
    use App\Repositories\UserRepository;
    use MikeZange\LaravelEntityRepositories\Repositories\Cache\CacheBaseDecorator;
    
    class CacheUserDecorator extends CacheBaseDecorator implements UserRepository
    {
        public function __construct(UserRepository $repository)
        {
            parent::__construct();
            $this->entityName = 'user';
            $this->repository = $repository;
        }
    }
    

    class UserController extends Controller
    {
        /**
         * @var UserRepository
         */
        private $userRepository;
    
        /**
         * Create a new controller instance.
         *
         * @param UserRepository $userRepository
         */
        public function __construct(UserRepository $userRepository)
        {
            $this->userRepository = $userRepository;
        }
        
        public function index(Request $request)
        {
            $users = $this->userRepository->all();
            return $users;
        }
    }