PHP code example of eilander / repository

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

    

eilander / repository example snippets



'providers' => [
    ...
    Eilander\Repository\Providers\RepositoryServiceProvider::class,
],



   "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/",
            "Eilander\\Repository\\": "../library/eilander/repository/src/"
        }
    },

#!json

composer dump-autoload


    public function register()
    {
        // Bind FruitRepository interface to Elasticsearch\FruitRepository implementation
        $this->app->bind('Modules\Api\Repositories\FruitRepository', 'Modules\Api\Repositories\Elasticsearch\FruitRepository');
        $this->app->bind('Modules\Api\Repositories\FruitRepository', 'Modules\Api\Repositories\Eloquent\FruitRepository');
    }

$posts = $this->repository->query($selection = '');

http://www.url.nl?filter={"provider":["kpn","vodafone"],"betweenDate":["2015-01-01","2015-12-31"]}

$posts = $this->repository->all();

$posts = $this->repository->paginate($limit = null, $columns = ['*']);

$post = $this->repository->find($id);

$post = $this->repository->with(['state'])->find($id);

$posts = $this->repository->findByField('country_id','15');

$posts = $this->repository->where([
    //Default Condition =
    'state_id'=>'10',
    'country_id'=>'15',
    //Custom Condition
    ['columnName','>','10']
]);

$this->repository->delete($id)

[
    {
        "id": 1,
        "name": "John Doe",
        "email": "[email protected]",
        "created_at": "-0001-11-30 00:00:00",
        "updated_at": "-0001-11-30 00:00:00"
    }
]


namespace App\Http\Controllers;

use Eilander\Repository\Listeners\EloquentClearCache;
use App\Http\Controllers\Controller;
use App\Http\Requests\FruitRequest;
use App\Repositories\FruitRepository;

class FruitController extends Controller {

    /**
     * @var FruitRepository
     */
    protected $repository;

    public function __construct(FruitRepository $repository){
        $this->repository = $repository;
    }
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        // cache for 15 minutes
        $fruits = $this->repository->minutes(15)->paginate(50);
        or
        // cache for 6 hours
        $fruits = $this->repository->hours(6)->paginate(50);
        or
        // cache for 4 days
        $fruits = $this->repository->days(4)->paginate(50);


        return view('fruits.index', compact('fruits'));
    }