ptrml/polycomments

Laravel 5+ 的通用评论系统

dev-master 2016-09-15 12:37 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:15:34 UTC


README

利用多态关系实现的简单可挂载评论系统。 非常原始的预 alpha 版本。任何时间都可能发生重大变化。

##安装

###步骤 1:后端 ####通过 composer 安装

composer require ptrml/polycomments "dev-master"

####在 conf/app.php 中注册服务提供者

'providers' => [
...
Ptrml\Polycomments\PolycommentsServiceProvider::class,
...
],

####发布资源和迁移

php artisan vendor:publish --tag=polycomments
php artisan migrate

####在您的模型上实现接口和特性

class Post extends Model implements CommentableInterface
{
    use Commentable;
    ...
}

(将 Post 模型替换为您的模型)

###步骤 2:前端 ####将 PolycommentsController.php 添加到您的调用中(Post 是示例模型)

class PolycommentsController extends Controller
{
    function commentPost(Request $request,$id)
    {
        Commenter::comment(Post::find($id),$request);
        return redirect("home");
    }
    ...
}

(将 Post 模型替换为您的模型) ####添加路由

Route::post('/polycomments/post/{id}', 'PolycommentsController@commentPost')->name('polycomments.post');

####将预先制作的评论块添加到您模型的视图中

@include('polycomments::polycomments',['polycomments_subject'=>$post,'polycomments_route'=>'polycomments.post'])

(polycomments_subject 是您的模型实例,polycomments_route 是命名路由)

###步骤 3:定制 ####编辑 views/vendor/polycomments/* 以自定义外观和感觉


###享受





许可

MIT 许可证.