Introduction

When using laravel, I was shocked by the power of laravel. In the development of laravel projects, the artisan command is often used. How to use it and how to make it silky, especially when creating a Controller or Model, is really convenient, but in the company The problem often encountered is that the project will abstract the Service, Repository layer, etc., is there a way to create it as smoothly as the artisan command? So the Composer extension package was developed.

installation

composer require sockstack/laragen --dev

use

# 创建 service
php artisan make:service {name}
# 创建 repository
php artisan make:repository {name}
  • Case number one
php artisan make:repository UserRepository

Generate UserRepository.php in the app/Repositories directory, the content is as follows:

<?php

namespace App\Repositories;

class UserRepository
{
    public function __construct()
    {
        parent::__construct();
    }
}
  • Case two
php artisan make:repository User/UserRepository

Generate UserRepository.php in the app/Repositories/User directory, the content is as follows:

<?php

namespace App\Repositories\User;

class UserRepository
{
    public function __construct()
    {
        parent::__construct();
    }
}
  • Case three
php artisan make:service UserService

Generate a UserService.php file in the app/Services directory, the content is as follows:

<?php

namespace App\Services;

class UserService
{
    public function __construct()
    {
        parent::__construct();
    }
}
  • Case four
php artisan make:service User/UserService

Generate UserService.php in the app/Services/User directory, the content is as follows:

<?php

namespace App\Services\User;

class UserService
{
    public function __construct()
    {
        parent::__construct();
    }
}

潇尘渊
77 声望19 粉丝

会点php,java,go的菜鸡程序猿