大飞_dafei

导航

laravel Console 层---命令使用 && php artisan

1). commands 文件使用

创建文件   php artisan make:command test
命令名字   protected $signature = 'command:name';
执行    php artisan command:name


在一个commands 文件中执行对应的方法
protected $signature = 'command {foo}';   //注意这里写法即可
php artisan command bar  //执行命令
    
//--------- demo -----  
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class foo extends Command
{
    // protected $signature = 'foo';
    protected $signature = 'command {foo}';
    protected $description = 'foo class Command description';

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

    //php artisan foo
    public function handle()
    {
        // echo "hello foo "; //sb 的laravel调用对应的方法,需要用判断写
        $method = $this->argument('foo');
        if (method_exists($this, $method)) {
            $this->$method();
            echo "执行完成\n";
        }else{
            echo "${method} is not exists\n";
        }
    }

    //php artisan command bar
    public function bar()
    {
        echo "bar";
    }
}
    

02)

php artisan list  #显示命令列表
php artisan config    #这个可以看懂config的参数
php artisan config:clear    #清除配置文件缓存
php artisan config:cache   #配置文件缓存
php artisan route:cache    #路由缓存,路由中不能有闭包

php artisan --version  #查看laravel版本
php artisan -V         #查看laravel版本

php artisan view:cache  #view层生成缓存
php artisan view:clear  #view层清除缓存

03)

生成model层
php artisan infyom:model model名字
demo:
php artisan infyom:model Admin
---------如下
$ php artisan infyom:model Admin
Specify fields for the model (skip id & timestamp fields, we will add it automat
ically)
Read docs carefully to specify field inputs)
Enter "exit" to finish

 Field: (name db_type html_type options) []:
 > name string

 Enter validations:  []:
 > required

 Field: (name db_type html_type options) []:
 > exit


Model created:
Admin.php
Generating autoload files
---------

 

 

#model层生成
php artisan infyom:model 模型名称 --fromTabel --tableName=表名(需要表前缀)
php artisan infyom:model DicRegion --fromTable --tableName=jyt_dic_region
#model层生成,windwos中特定PHP版本
D:\php\php7.2.9nts\php.exe artisan infyom:model DicRegion --fromTable --tableName=jyt_dic_region

 

#model层生成
php artisan infyom:model 模型名称 --fromTabel --tableName=表名(需要表前缀)
php artisan infyom:model DicRegion --fromTable --tableName=jyt_dic_region

https://laravelacademy.org/post/3716.html

安装这个包
laravel-generator
laravel-generator
"infyomlabs/laravel-generator": "5.6.x-dev",

http://labs.infyom.com/laravelgenerator/docs/5.6/installation
http://labs.infyom.com/laravelgenerator/docs/5.6/installation

参考地址:  model层 

 快速为 Laravel 应用生成CRUD、API、测试用例代码

laravelgenerator

posted on 2020-10-14 09:17  大飞_dafei  阅读(382)  评论(0编辑  收藏  举报