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

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

app/Traits/Sluggable.php:

namespace App\Traits;

trait Sluggable
{
    //
}
人生就是马拉松,精彩的是后半程
running8
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 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个月前 评论

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