PHP code example of gerfey / repository

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

    

gerfey / repository example snippets


 namespace App;

use Illuminate\Database\Eloquent\Model;

class Test extends Model
{

}

 namespace App\Repository;

use Gerfey\Repository\Repository;
use App\Test;

class TestRepository extends Repository {
    protected $entity = Test::class;
}



namespace App\Criteria;

use Gerfey\Repository\Contracts\Criteria\CriteriaInterface;
use Illuminate\Database\Eloquent\Builder;

class TestActiveCriteria implements CriteriaInterface
{
    public function apply($model): Builder
    {
        return $model->limit(10);
    }
}

 namespace App\Http\Controllers;

use App\Repository\TestRepository;
use App\Criteria\TestActiveCriteria;

class TestController extends Controller {

    public function index(TestRepository $testRepository) {    
        $testRepository->addCriteria(new TestActiveCriteria());        
        $testRepository->addCriteria(TestActiveCriteria::class);        
        return \Response::json($testRepository->all());
    }
}
bash
 php artisan make:repository Test
 
bash
 php artisan make:repository:criteria TestActive