Laravel 11: 新的 Artisan 命令 "make:trait"

Laravel 11引入了新的Artisan命令 make:trait
与每个 Artisan 命令一样,您可以传递要创建的文件名,也可以保留为空,Laravel 会询问。

app/Traits/Sluggable.php:

namespace App\Traits;

trait Sluggable
{
    //
}
人生就是马拉松,精彩的是后半程
running8
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
讨论数量: 7
sanders

为什么要专门建立 App\Traits 命名空间?谁能来讲一下?我的习惯是与要使用的类型放到相同的命名空间下。比如:

app/Models
├── Eloquent.php
├── Goods
│   ├── Brand.php
│   └── Category.php
├── Scopes
│   ├── HasAddress.php <- trait
│   ├── HasCode.php <- trait
│   ├── HasName.php <- trait
│   ├── HasNest.php <- trait
│   ├── HasSpatialDistrict.php <- trait
│   └── ScopeLogic.php
├── Shop
│   └── Shop.php
├── Spatial
│   └── District.php
└── User.php
1个月前 评论
MArtian 1个月前
sanders (作者) 1个月前
Asuna 1个月前
sanders (作者) 1个月前
MArtian 1个月前

这个命令没什么意义

1个月前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!