Wallogit.com
2017 © Pedro Peláez
This package is a experimental project inspired by yish/generators which extends the core file generators based on Laravel 5. It can help you build classes with basic Model-Repository-Service pattern.
This package is a experimental project inspired by yish/generators which extends the core file generators based on Laravel 5 It can help you build classes with basic Model-Repository-Service pattern., (*1)
Install by composer, (*2)
$ composer require chihchenghuang/laravel-mrs-generators
Registing Service Provider, (*3)
``` php <?php, (*4)
//app.php, (*5)
'providers' => [, (*6)
/*
* Laravel MRS Generators Service Provider
*/
\ChihCheng\MRSGenerators\GeneratorsServiceProvider::class,
],
or
``` php
<?php
//app/Providers/AppServiceProvider.php
public function register()
{
if ($this->app->environment() == 'local')
{
/*
* Laravel MRS Generators Service Provider
*/
$this->app->register( \ChihCheng\MRSGenerators\GeneratorsServiceProvider::class );
}
}
This command will generate a repository class., (*7)
$ php artisan make:repository Repositories/TestRepository
This command will generate a service class., (*8)
$ php artisan make:repository Services/TestService
This command will generate classes based on the corresponding Model-Repository-Service Pattern Set. It will create files like the example pattern below by using only one command:, (*9)
$ php artisan make:mrs-model Test
namespace App\Models;, (*10)
use Illuminate\Database\Eloquent\Model;, (*11)
class Test extends Model { // }, (*12)
* app/Repositories/TestRepository.php
``` php
<?php
namespace App\Repositories;
use App\Models\Test;
class TestRepository
{
protected $test;
public function __construct( Test $test )
{
$this->test = $test;
}
}
namespace App\Services;, (*13)
use App\Repositories\TestRepository;, (*14)
class TestService { protected $testRepository;, (*15)
public function __construct( TestRepository $testRepository )
{
$this->testRepository = $testRepository;
}
}, (*16)
```, (*17)