isthegeek / laravel-commentable
允许将带级联的评论添加到多个和不同的模型中。
这个软件包的规范仓库似乎已消失,因此该软件包已被冻结。
2.0
2017-01-07 14:18 UTC
Requires
- php: >=5.4
- baum/baum: ~1.1
- illuminate/database: ~5.0
- illuminate/support: ~5.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-03-11 12:35:36 UTC
README
为Laravel 4和5的应用程序中的多个和不同的模型添加带级联的评论。
对于Laravel 4,请查看 1.0分支。
该软件包使用嵌套集合模式与Baum。
安装
编辑您的项目composer.json文件以要求isthegeek/laravel-commentable
。
"require": {
"isthegeek/laravel-commentable": "~2.0"
}
接下来,从终端更新Composer。
composer update
与大多数Laravel软件包一样,您需要注册Commentable 服务提供者。在您的config/app.php
中,将'Isthegeek\Commentable\CommentableServiceProvider'
添加到$providers
数组末尾。
'providers' => [ 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', ... 'Isthegeek\Commentable\CommentableServiceProvider', ],
入门
在正确安装软件包后,您需要生成迁移。
php artisan commentable:migration
它将生成<timestamp>_create_comments_table.php
迁移。现在您可以使用Artisan迁移命令运行它
php artisan migrate
迁移后,将出现一个新表,comments
。
用法
您需要在您的模型上设置它作为可评论的。
<?php namespace App; use Isthegeek\Commentable\Commentable; use Illuminate\Database\Eloquent\Model; class Post extends Model { use Commentable; }
现在,您的模型可以访问comments
方法。
$post = Post::first(); $comment = new Isthegeek\Commentable\Comment; $comment->body = 'My first comment!'; $comment->user_id = \Auth::id(); $post->comments()->save($comment); dd(Post::first()->comments);
有关带级联评论的所有信息,请参阅Baum文档。