outl1ne / nova-notes-field
此 Laravel Nova 扩展包为 Nova 的字段工具箱添加了注释字段。
3.1.0
2023-08-18 14:07 UTC
Requires
- php: >=8.0
- laravel/nova: ^4.0
- outl1ne/nova-translations-loader: ^5.0
- dev-main
- 3.1.0
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/express-4.19.2
- dev-dependabot/npm_and_yarn/webpack-dev-middleware-5.3.4
- dev-dependabot/npm_and_yarn/follow-redirects-1.15.6
This package is auto-updated.
Last update: 2024-08-28 21:56:44 UTC
README
此 Laravel Nova 扩展包为 Nova 的字段工具箱添加了注释字段。
需求
php: >=8.0
laravel/nova: ^4.0
特性
- 详情页上的注释字段
- 区分用户添加和系统添加的注释
- 通过 UI 或编程方式添加注释的能力
- 编辑用户创建的注释的能力
- 删除用户创建的注释的能力(带确认对话框)
- 支持自定义占位符
- 设置隐藏或显示“添加注释”按钮的能力
屏幕截图
安装
# Install the package via Composer composer require outl1ne/nova-notes-field # Run automatically loaded migration(s) php artisan migrate
使用
将 HasNotes
特性添加到包含注释的模型中
use Outl1ne\NovaNotesField\Traits\HasNotes; class ExampleModel extends Model { use HasNotes; }
将 NotesField
添加到相应的资源中
use Outl1ne\NovaNotesField\NotesField; class SomeResource extends Resource { // ... public function fields(Request $request) { return [ // ... NotesField::make('Notes') ->placeholder('Add note') // Optional ->addingNotesEnabled(false) // Optional ->fullWidth(), // Optional ] } }
编程添加注释
要编程添加注释,请使用 HasNotes
特性提供的方法
/** * Creates a new note and attaches it to the model. * * @param string $note The note text which can contain raw HTML. * @param bool $user Enables or disables the use of `Auth::user()` to set as the creator. * @param bool $system Defines whether the note is system created and can be deleted or not. * @return \Outl1ne\NovaNotesField\Models\Note **/ public function addNote($note, $user = true, $system = true)
编程编辑注释
要编程编辑注释,请使用 HasNotes
特性提供的 editNote
方法
/** * Edit a note with the given ID and text. * * @param int|string $noteId The ID of the note to edit. * @param string $text The note text which can contain raw HTML. * @return \Outl1ne\NovaNotesField\Models\Note **/ public function editNote($noteId, $text)
或者,您可以通过标准的 Eloquent 方法简单地更新内存中已有的 Note 记录
$note = $notable->notes()->where('id', '=', $noteId)->first(); $note->update([ 'text' => $noteText, ]); // Or... $note->text = $noteText; $note->save();
配置
发布配置
您可以通过运行以下命令发布配置:
php artisan vendor:publish --provider="Outl1ne\NovaNotesField\NotesFieldServiceProvider" --tag="config"
可用的配置选项
自定义编辑和删除授权
默认情况下,只有写下注释的用户可以编辑/删除它,并且没有人可以编辑/删除系统注释。
您可以通过定义一个名为 edit-nova-note
和 delete-note-note
的新 Laravel 授权网关来定义哪些用户可以编辑/删除哪些注释。
在您的 AuthServiceProvider.php
中添加类似以下内容的网关定义
use Illuminate\Support\Facades\Gate; use Outl1ne\NovaNotesField\Models\Note; // ... public function boot() { Gate::define('edit-nova-note', function ($user, Note $note) { // Do whatever here to add custom edit authorization logic, ie: return $note->created_by === $user->id || $user->isAdmin; }); Gate::define('delete-nova-note', function ($user, Note $note) { // Do whatever here to add custom delete authorization logic, ie: return $note->created_by === $user->id || $user->isAdmin; }); }
本地化
可以使用以下发布命令发布翻译文件
php artisan vendor:publish --provider="Outl1ne\NovaNotesField\NotesFieldServiceProvider" --tag="translations"
您可以将翻译添加到 resources/lang/vendor/nova-notes-field/
中,通过创建一个具有区域名称的新翻译文件(例如 se.json
)并将 JSON 从现有的 en.json
复制过来。
发布迁移(可选)
如果您想编辑迁移,可以像这样发布迁移:
php artisan vendor:publish --provider="Outl1ne\NovaNotesField\NotesFieldServiceProvider" --tag="migrations"
致谢
许可证
此项目是开源软件,许可协议为 MIT 协议。