mveabraham/repository-generator
最新稳定版本:v1.0.3
Composer 安装命令:
composer require mveabraham/repository-generator
包简介
Generate Repository from Eloquent models
README 文档
README
Laravel Repositories generator is a package for Laravel 7, 8 and 9 which is used to generate reposiotries from eloquent models.
Installation
Run the following command from you terminal:
composer require "mveabraham/repository-generator"
Usage
First, generate your repositories class from eloquent models in Models folder.
php artisan make:repositories
And finally, use the repository in the controller:
<?php namespace App\Http\Controllers; use App\Repositories\PostRepository; class PostController extends Controller { private $postRepository; public function __construct(PostRepository $postRepository) { $this->postRepository = $postRepository; } public function index() { return response()->json($this->postRepository->getAll()); } }
Available Methods
The following methods are available:
MveAbraham\RepositoryGenerator\RepositoryInterface
public function exists(string $key, $value, $withTrashed = false) public function getByAttribute(string $attr_name, $attr_value, $relations = [], $withTrashed = false, $selects = []) public function getPaginate(int $n, $relations = [], $withTrashed = false, $selects = []); public function store(Array $inputs) public function getById($id, $relations = [], $withTrashed = false, $selects = []) public function search($key, $value, $relations = [], $withTrashed = false, $selects = []) public function getAll($relations = [], $withTrashed = false, $selects = []) public function countAll($withTrashed = false) public function getAllSelectable($key) public function update($id, Array $inputs) public function destroy($id) public function destroyAll() public function forceDelete($id) public function restore($id)
Example usage
Create a new post in repository:
$post = $this->postRepository->store($request->all());
Update existing post:
$post = $this->postRepository->update($post_id, $request->all());
Delete post:
$post = $this->postRepository->destroy($id);
Get post by post_id:
$post = $this->postRepository->getById($id);
you can also chose what relations to eager load:
$post = $this->postRepository->getById($id, ['comments']);
Credits
This package is inspired by this great package by @bosnadev.
统计信息
- 总下载量: 48
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-02