shintarosakata / laravel-repository
v1.1.2
2019-09-22 00:24 UTC
Requires
- php: >=7.2
- laravel/framework: ~6.0
Requires (Dev)
- orchestra/testbench: ^4.0
- dev-master
- v1.1.2.x-dev
- v1.1.2
- v1.1.1.x-dev
- v1.1.1
- v1.0.1.x-dev
- v1.0.0.x-dev
- v1.0.0
- 0.0.0.x-dev
- dev-dependabot/composer/symfony/http-kernel-4.4.39
- dev-dependabot/composer/laravel/framework-6.18.43
- dev-dependabot/composer/symfony/http-foundation-4.4.1
- dev-dependabot/composer/symfony/mime-4.4.1
- dev-analysis-zR5yyD
- dev-pr-test
- dev-add_entity_test
- dev-analysis-8P4xZK
- dev-add_repository_test
- dev-analysis-XWENLV
- dev-add_tests
- dev-analysis-8nONPG
- dev-fix_phpunit
- dev-add_make_command_test
- dev-analysis-8nRYb5
- dev-analysis-z92M1N
- dev-add_test
This package is auto-updated.
Last update: 2024-10-26 06:01:38 UTC
README
About
framework for building repository pattern in Laravel.
Requirements
requires Laravel 6.0
Usage
Installation
$ composer require shintarosakata/laravel-repository
Artisan Commands
$ artisan make:repository <name>
$ artisan make:interface <name>
$ artisan make:entity <name>
$ artisan make:repositoryProvider <name>
RepositoryProvider is for binding repository and interface
Quick start
1. make repository, interface, entity and provider
Entity name -> singular
Other -> plural
$ artisan make:entity Sample
entity created successfully.
$ artisan make:repository Samples
repository created successfully.
$ artisan make:interface Samples
repository created successfully.
$ artisan make:repositoryProvider RepositoryProvider
Provider created successfully.
↓
.
└── app
├── Entities
│ └── Sample.php
│
├── Repositories
│ ├── Samples.php
│ └── SamplesInterface.php
│
└── Providers
└── RepositoryProvider
2. Binding Interfaces To Implementations
<?php namespace App\Providers; use shintarosakata\LaravelRepository\RepositoryProvider\RepositoryProvider as upstreamRepositoryProvider; class RepositoryProvider extends upstreamRepositoryProvider { // ... protected $repositories = [ 'Samples', // Add <name> here ]; // ...
Register provider
./config/app.php
<?php return [ // ... 'providers' => [ // ... App\Providers\RepositoryProvider::class, // register provider ], // ... ];
3. Defining Repositories
<?php namespace App\Repositories\Samples; use shintarosakata\LaravelRepository\Repository\Repository; use Illuminate\Database\Eloquent\Collection; use App\Entities\Sample; class Samples extends Repository implements SamplesInterface { protected $table = 'samples'; // Add DB Table name here public function fetchFirst(): Sample { return $this->builder->first(); } public function fetchAll(): Collection { return $this->builder->get(); } }
4. Defining Interface
<?php namespace App\Repositories\Samples; use shintarosakata\LaravelRepository\Repository\RepositoryInterface; use Illuminate\Database\Eloquent\Collection; use App\Entities\Sample; interface SamplesInterface extends RepositoryInterface { // Add public functions here... public function fetchFirst(): Sample; public function fetchAll(): Collection; }
5. Defining Entity
<?php namespace App\Entities; use shintarosakata\LaravelRepository\Entity\Entity as upstreamEntity; class Sample extends upstreamEntity { // Add behavior here... }
6. use!
<?php namespace App\Http\Controllers; use App\Repositories\Samples\SamplesInterface; class SampleController extends Controller { private $samples_repository; // Dependency injection public function __construct(SamplesInterface $samples_repository) { $this->samples_repository = $samples_repository; } public function index() { $first_sample_entity = $this->samples_repository->fetchFirst(); return view('sample.index', $first_sample_entity); } }
Contributing
Thank you for considering contributing to the Laravel-Repository
please send an e-mail to Shintaro Sakata shintaro.sakata@leverages.com.
Security Vulnerabilities
If you discover a security vulnerability within Laravel-Repository, please send an e-mail to Shintaro Sakata shintaro.sakata@leverages.com. All security vulnerabilities will be promptly addressed.
License
Laravel-Repository is open-source software licensed under the MIT license.