承接 thuanpt/larasitory 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thuanpt/larasitory

Composer 安装命令:

composer require thuanpt/larasitory

包简介

A repository pattern simple for Laravel

README 文档

README

To get started with Base Repository, use Composer to add the package to your project's dependencies:

    composer require thuanpt/larasitory

Basic Usage

Next, you are ready to use repository. If you want create repository with Model corresponding (example: PostRepository), run commnand line:

php artisan make:repostitory PostRepository -i

When run this commnand, Packeage automatic generate two file in forder Repository: PostRepository and PostRepositoryInterface. PostRepository extends BaseRepository so you can use method in BaseRepository

<?php

namespace App\Repositories;

use App\Models\Post;
use Larasitory\Repository\BaseRepository;
use App\Repositories\Contracts\PostRepositoryInterface;

class PostRepository extends BaseRepository implements PostRepositoryInterface
{
    /**
     * Set model database
     *
     * @return mixed|string
     */
    public function model()
    {
        return Post::class;
    }
}

Register in AppServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(
            \App\Repositories\Contracts\PostRepositoryInterface::class,
            \App\Repositories\PostRepository::class
        );
    }
}

Use in controller

In controller, You want find post by id use repository

<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Repositories\Contracts\PostRepositoryInterface;

class PostController extends Controller
{
    /**
     * @var \App\Repositories\PostRepository
     */
    private $postRepository;

    public function __construct(PostRepositoryInterface $postRepository )
    {
        $this->postRepository = $postRepository;
    }

    public function show($id) 
    {
        $user = $this->postRepository->getById($id);

        return response()->json($user);
    }
}

统计信息

  • 总下载量: 61
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固