dev-master
9999999-devCommentable trait for laravel 5.5
The Requires
The Development Requires
by keggermont
Commentable trait for laravel 5.5
Use Composer :, (*1)
``` bash $ composer require k-eggermont/laravel-commentable, (*2)
Publish the vendor assets:
php artisan vendor:publish --provider="Keggermont\Commentable\CommentableServiceProvider" php artisan migrate, (*3)
## Configuration You can configure the package on /config/laravel-commentable.php ## Usage ### Api By default, the api is accessible at /api/comments/. You have 3 routes : * GET /api/comments/{type}/{id} : Get comments * POST /api/comments/create/{type}/{id} : Create a new comment (data required : title and body) * DELETE /api/comments/{comment_id} : Delete a comment (if you are the owner, OR if you are an admin (User->is_admin = true)) ### Include trait for your model ``` php <?php namespace App; use Keggermont\Commentable\Traits\Commentable; use Illuminate\Database\Eloquent\Model; class MyModel extends Model { use Commentable; }
<?php $allowType = [ "comment" => \Keggermont\Commentable\Models\Comment::class, "mymodel" => App\MyModel::class ]
``` php $object = MyModel::first();, (*4)
$comment = $post->createComment([ 'title' => 'Some title', 'body' => 'Some body', ], Auth::user());, (*5)
dd($comment);, (*6)
### Update a comment ``` php $idComment = 1; $comment = $post->updateComment($idComment, [ 'title' => 'new title', 'body' => 'new body', ]);
``` php // From trait : $post->deleteComment(1);, (*7)
// From object 'Comment' $comment->delete(); ```, (*8)
MIT, (*9)
Commentable trait for laravel 5.5