定制 rumspeed/laravel-notes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rumspeed/laravel-notes

最新稳定版本:v1.2.0

Composer 安装命令:

composer require rumspeed/laravel-notes

包简介

Add notes to your Eloquent models

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Easily add notes to your Eloquent models.

Installation

You can install the package via composer:

composer require rumspeed/laravel-notes

You can publish and run the migrations with:

php artisan vendor:publish --tag="notes-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="notes-config"

This is the contents of the published config file:

return [

    /* -----------------------------------------------------------------
     |  Models
     | -----------------------------------------------------------------
     */

    'authors' => [
        'table' => 'users',
        'model' => App\Models\User::class,
    ],

    'notes' => [
        'table' => 'notes',
        'model' => Rumspeed\LaravelNotes\Models\Note::class,
    ],
];

Usage

First things first, edit your eloquent model by using the Rumspeed\LaravelNotes\Traits\HasManyNotes trait.

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Rumspeed\LaravelNotes\Traits\HasManyNotes;

class Post extends Model {
    use HasManyNotes;

    // Other stuff ...
}

You can also use the Rumspeed\LaravelNotes\Traits\HasOneNote trait if you want to manage one note for your model.

Add a note to a model.

You can call the createNote() method on your Eloquent model like below:

$post = App\Post::first();
$note = $post->createNote('Hello world #1');

Add With a Author/ User

$user = App\User::first();
$post = App\Post::first();
$note = $post->createNote('Hello world #1', $user);

You can also specify how you want to add the author id by using the getCurrentAuthorId():

<?php namespace App;

use Illuminate\Database\Eloquent\Model;
use Rumspeed\LaravelNotes\Traits\HasManyNotes;

class Post extends Model {
    use HasManyNotes;

    // Other stuff ...

    /**
     * Get the current author's id.
     *
     * @return int|null
     */
     protected function getCurrentAuthorId()
     {
         return auth()->id();
     }
}

Getting Notes

$post  = App\Post::first();
$notes = $post->notes;

NOTE : $post->notes relation property is only available in the HasManyNotes trait. If you're using HasOneNote trait, use $post->note instead.

Getting the author's notes

You can also retrieve all the author's notes by using the Rumspeed\LaravelNotes\Traits\AuthoredNotes Trait in your User model (for example).

$user = App\User::first();
$post = App\Post::first();
$post->createNote('Hello world #1', $user);

$notes = $user->authoredNotes;

Finding a note with a specific ID

$post = App\Post::first();
$note = $post->findNote(1);

NOTE : The findNote() method is only available in the HasManyNotes trait.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 297
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固