承接 outl1ne/nova-notes-field 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

outl1ne/nova-notes-field

Composer 安装命令:

composer require outl1ne/nova-notes-field

包简介

This Laravel Nova package adds a notes field to Nova's arsenal of fields.

README 文档

README

Latest Version on Packagist Total Downloads

This Laravel Nova package adds a notes field to Nova's arsenal of fields.

Requirements

  • php: >=8.0
  • laravel/nova: ^4.0

Features

  • Notes field on Detail view
  • Differentiation between user-added and system-added notes
  • Ability to add notes through the UI or programmatically
  • Ability to edit user-made notes
  • Ability to delete user-made notes (w/ confirmation modal)
  • Customizable placeholder support
  • Set ability to hide or show the 'Add Note' button

Screenshots

Detail view

Installation

# Install the package via Composer
composer require outl1ne/nova-notes-field

# Run automatically loaded migration(s)
php artisan migrate

Usage

Add HasNotes trait to the model that has the notes:

use Outl1ne\NovaNotesField\Traits\HasNotes;

class ExampleModel extends Model
{
    use HasNotes;
}

Add NotesField to the matching resource:

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
    ]
  }
}

Adding notes programmatically

To add notes programmatically, use the method provided by the HasNotes trait:

/**
 * 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::guard(config('nova.guard'))->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)

Editing notes programmatically

To edit notes programmatically, use the editNote method provided by the HasNotes trait:

/**
 * 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)

Alternatively, you can simply update an existing Note record that's already in memory via standard Eloquent methods:

$note = $notable->notes()->where('id', '=', $noteId)->first();

$note->update([
    'text' => $noteText,
]);

// Or...
$note->text = $noteText;
$note->save();

Configuration

Publish configuration

You can publish the configuration by running:

php artisan vendor:publish --provider="Outl1ne\NovaNotesField\NotesFieldServiceProvider" --tag="config"

The available configuration option(s):

Config Type description
get_avatar_url callable or string Either enter the url attribute name on your model or a callable which allows you to generate your own URL for the user. The input parameter is the user model. By default, Gravatar is used for the user's avatars.
table_name string Optionally provide your own table name for the notes table. Default is nova_notes.
notes_model string Optionally provide your own Note model.
use_trix_input boolean Optionally enable Trix WYSIWYG input by setting this to true.
full_width_inputs boolean Optionally force all notes fields to display in full width.
display_order string Optionally set the sort order for notes. Default is DESC.

Custom edit & delete authorization

By default, only the user that wrote the note can edit/delete it and no one can edit/delete system notes.

You can define which user(s) can edit/delete which notes by defining a new Laravel authorization Gate called edit-nova-note and delete-note-note respectively.

In your AuthServiceProvider.php add a Gate definition like so:

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;
  });
}

Localization

The translation file(s) can be published by using the following publish command:

php artisan vendor:publish --provider="Outl1ne\NovaNotesField\NotesFieldServiceProvider" --tag="translations"

You can add your translations to resources/lang/vendor/nova-notes-field/ by creating a new translations file with the locale name (ie se.json) and copying the JSON from the existing en.json.

Publishing migrations (optional)

If you want to edit the migration(s), you can publish the migrations like so:

php artisan vendor:publish --provider="Outl1ne\NovaNotesField\NotesFieldServiceProvider" --tag="migrations"

Credits

License

This project is open-sourced software licensed under the MIT license.

outl1ne/nova-notes-field 适用场景与选型建议

outl1ne/nova-notes-field 是一款 基于 Vue 开发的 Composer 扩展包,目前已累计 160.82k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2022 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「nova」 「laravel」 「field」 「outl1ne」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 outl1ne/nova-notes-field 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 outl1ne/nova-notes-field 我们能提供哪些服务?
定制开发 / 二次开发

基于 outl1ne/nova-notes-field 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 160.82k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 52
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 52
  • Watchers: 4
  • Forks: 40
  • 开发语言: Vue

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-10