1. Go to this page and download the library: Download prettus/laravel-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/ */
prettus / laravel-repository example snippets
'Prettus\Repository\RepositoryServiceProvider',
class Post extends Eloquent { // or Ardent, Or any other Model Class
protected $fillable = [
'title',
'author',
...
];
...
}
use Prettus\Repository\Eloquent\Repository;
class PostRepository extends Repository {
public function __construct(Post $model)
{
parent::__construct($model);
}
}
class PostsController extends BaseController {
/**
* @var PostRepository
*/
protected $repository;
public function __construct(PostRepository $repository){
$this->repository = $repository;
}
....
}
use Prettus\Repository\Eloquent\Repository;
class PostRepository extends Repository {
public function __construct(Post $model)
{
parent::__construct($model);
}
public function boot(){
$this->pushCriteria(new MyCriteria());
$this->pushCriteria(new AnotherCriteria());
...
}
}
use Prettus\Repository\Eloquent\Repository;
use Prettus\Repository\Criteria\RequestCriteria;
class PostRepository extends Repository {
/**
* @var array
*/
protected $fieldSearchable = [
'name',
'email'
];
public function __construct(Post $model)
{
parent::__construct($model);
}
public function boot(){
$this->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
...
}
}
public function index()
{
$this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
$posts = $this->repository->all();
...
}