当前位置:网站首页>Laravel creates a service layer
Laravel creates a service layer
2022-06-24 23:12:00 【Wang Daochang's way of programming】
One 、 Generation and editing service file
php artisan make:command AddService
Execute the command , Will be in app\Console Generate under directory Commands Catalog , At the same time app\Console\Commands Generate under directory AddService.php file .
take AddService.php Empty file contents , And replace with the following
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
class AddService extends GeneratorCommand
{
/** * Console command name * * @var string */
protected $name = 'make:service';
/** * Console command description * * @var string */
protected $description = 'Create a new service class';
/** * The type of the generated class * * @var string */
protected $type = 'Services';
/** * Get the stub file of the generator * * @return string */
protected function getStub()
{
return __DIR__.'/stubs/service.stub';
}
/** * Get the default namespace of the class * * @param string $rootNamespace * @return string */
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Services';
}
}
Two 、 Create stub directories and files
stay app\Console\Commands Create under directory Stubs Catalog , You can right-click to create a new folder , Or use the command line mkdir app\Console\Commands\Stubs Add a directory named services.stub The file of , The full path is app/Console/Commands/Stubs/service.stub
edit services.stub And add content , Add the following to services.stub File and save .
<?php
namespace DummyNamespace;
class DummyClass
{
}
3、 ... and 、 Registration order
Add the following to app/Console/Kernel.php Of documents protected $commands = [] Property array , To give effect to an order .
\App\Console\Commands\AddServices::class
protected $commands = [
Commands\AddService::class
];
Four 、 The test command
php artisan make:service MusicService
边栏推荐
- Paddledtx v1.0 has been released, and its security and flexibility have been comprehensively improved!
- Cases of addition, deletion, modification and search of C # learning for two years and C # import and export (de duplication)
- China solar window market trend report, technical dynamic innovation and market forecast
- Spark 离线开发框架设计与实现
- Environment configuration | vs2017 configuring openmesh source code and environment
- Parental delegation mechanism
- Getting started with the go Cobra command line tool
- Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
- MySQL kills 10 people. How many questions can you hold on to?
- Solve the problem of non secure websites requesting localhost to report CORS after chrome94
猜你喜欢
docker安装mysql-简单无坑
15 lines of code using mathematical formulas in wangeditor V5
EPICS记录参考2--EPICS过程数据库概念
加分利器 不负所托 | 知道创宇获攻防演练防守方感谢信!
Are you afraid of being asked MySQL related questions during the interview? This 30000 word essence summary + 100 interview questions, and it's enough to hang the interviewer
Canvas to add watermark to pictures
Talk about GC mechanism often asked in interview
Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
2022 simulated 100 questions and simulated examination of high-altitude installation, maintenance and demolition
Servlet
随机推荐
Attention, postgraduate candidates! They are the easiest scams to get caught during the preparation period?!
非单文件组件
动态菜单,自动对齐
Some updates about a hand slider (6-18, JS reverse)
How should we measure agile R & D projects?
How to submit the shopee opening and settlement flow?
EMI的主要原因-工模电流
监听 Markdown 文件并热更新 Next.js 页面
Building Survey [1]
Research Report on research and investment prospects of China's container coating industry (2022 Edition)
Dynamic menu, auto align
15 lines of code using mathematical formulas in wangeditor V5
Source code reading | the process of reading text format STL by openmesh
Laravel 认证模块 auth
Parental delegation mechanism
Analyze the implementation process of oauth2 distributed authentication and authorization based on the source code
JD 618 conference tablet ranking list announced that the new dark horse brand staff will compete for the top three, learning from Huawei, the leader of domestic products
【Laravel系列7.9】测试
Blogs personal blog test point (manual test)
并发之共享模型管程