大飞_dafei

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

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 模型名称 --fromTable --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   大飞_dafei  阅读(425)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示