PHP code example of srgafanhoto / pattern-repository
1. Go to this page and download the library: Download srgafanhoto/pattern-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/ */
srgafanhoto / pattern-repository example snippets
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $fillable = [
'title',
'author',
];
}
namespace App\Domains\Module\Repository;
use App\Post;
use srgafanhoto\PatternRepository\BaseRepository;
use srgafanhoto\PatternRepository\Criteria\Criteria;
use App\Domains\Module\Validators\UserValidation;
class PostRepository extends BaseRepository
{
protected function model()
{
return Post::class;
}
}
namespace App\Http\Controllers;
use App\Repositories\Contracts\PostRepository;
class PostsController extends Controller
{
protected $repository;
public function __construct(PostRepository $repository)
{
$this->repository = $repository;
}
}
$posts = $this->repository->all();
$post = $this->repository->find($id);
use srgafanhoto\PatternRepository\Criteria\Criteria;
$criteria = Criteria::create()
->fromRequest();
$this->repository->get($criteria);
$this->repository->paginate($criteria);
use srgafanhoto\PatternRepository\Criteria\Criteria;
class CustomCriteria extends Criteria
{
public function __construct($id)
{
$this->where('id', '=', $id);
}
}
$this->repository->get((new CustomCriteria(1))->where('autor', 'autor'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.