chihchenghuang / laravel-mrs-generators by chihchenghuang

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.
22
0
1
Package Data
Maintainer Username: chihchenghuang
Maintainer Contact: wesleycorta4@gmail.com (ChihCheng Huang)
Package Create Date: 2017-08-28
Package Last Update: 2017-09-07
Language: PHP
License: MIT
Last Refreshed: 2025-02-04 03:00:47
Package Statistics
Total Downloads: 22
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Laravel MRS Generators

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.

Installation

Install by composer

    $ composer require chihchenghuang/laravel-mrs-generators

Registing Service Provider

<?php

//app.php

'providers' => [
        
        /*
         * Laravel MRS Generators Service Provider
         */
        \ChihCheng\MRSGenerators\GeneratorsServiceProvider::class,

    ],

or

<?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 );

        }
    }

Example

Generate Repository:

This command will generate a repository class.

    $ php artisan make:repository Repositories/TestRepository

Generate Service:

This command will generate a service class.

    $ php artisan make:repository Services/TestService

Generate classes based on the corresponding Model-Repository-Service Pattern Set:

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:

    $ php artisan make:mrs-model Test
  • app/Models/Test.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Test extends Model
{
    //
}

  • app/Repositories/TestRepository.php
<?php

namespace App\Repositories;

use App\Models\Test;

class TestRepository
{
    protected $test;

    public function __construct( Test $test )
    {
        $this->test = $test;
    }

}

  • app/Services/TestService.php
<?php

namespace App\Services;

use App\Repositories\TestRepository;

class TestService
{
    protected $testRepository;

    public function __construct( TestRepository $testRepository )
    {
        $this->testRepository = $testRepository;
    }

}