2017 © Pedro Peláez
 

library commentable

Commentable trait for laravel 5.5

image

keggermont/commentable

Commentable trait for laravel 5.5

  • Sunday, May 13, 2018
  • by k-eggermont
  • Repository
  • 0 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel Commentable Trait

Installation

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

Configure the config/laravel-commentable.php

<?php
$allowType = [
"comment" => \Keggermont\Commentable\Models\Comment::class,
"mymodel" => App\MyModel::class
]

Create a comment from controller / model

``` 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', ]);

Delete a comment

``` php // From trait : $post->deleteComment(1);, (*7)

// From object 'Comment' $comment->delete(); ```, (*8)

License

MIT, (*9)

The Versions

13/05 2018

dev-master

9999999-dev

Commentable trait for laravel 5.5

  Sources   Download

The Requires

 

The Development Requires

by keggermont