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层
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 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 让容器管理更轻松!