2017 © Pedro Peláez
 

library mural

Laravel comment stream

image

laravolt/mural

Laravel comment stream

  • Thursday, August 4, 2016
  • by uyab
  • Repository
  • 1 Watchers
  • 10 Stars
  • 1,021 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 2 Open issues
  • 16 Versions
  • 7 % Grown

The README.md

Laravolt Mural

Travis-CI Build Status Coverage Status, (*1)

Laravolt Mural bertujuan menyediakan fitur komentar yang siap dipakai dan mudah diintegrasikan ke dalam aplikasi berbasis Laravel., (*2)

Package ini masih dalam tahap pengembangan dan belum dianjurkan untuk digunakan dalam produksi., (*3)

Requirement

  • Jquery
  • Semantic-ui or Bootstrap

Instalasi

Update composer.json

Untuk Laravel 5.2

Bisa dengan menjalankan perintah:, (*4)

composer require laravolt/mural

Atau menambahkan deklarasi berikut ke file composer.json:, (*5)

"require": {
    ...
    "laravolt/mural": "^1.0"
},

Untuk Laravel 5.1

Tambahkan deklarasi berikut ke file composer.json:, (*6)

"require": {
    ...
    "laravolt/mural": "^0.5"
}

Service Provider

Laravolt\Mural\ServiceProvider::class,

Facade

'Mural'  => Laravolt\Mural\Facade::class,

Migration

php artisan vendor:publish
php artisan migrate

Ini akan menambahkan file migrasi baru 2015_08_17_101000_create_comments_table.php sekaligus menjalan migrasi tersebut. Tabel baru bernama comments akan ditambahkan ke basisdata., (*7)

Config mural.php

Isi default_commentable dengan deklarasi class model yang bisa dikomentari, (*8)

'default_commentable' => \App\Post::class,

Penggunaan

Untuk setiap model yang bisa dikomentari, tambahkan trait dan interface seperti berikut:, (*9)

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Laravolt\Mural\CommentableTrait;
use Laravolt\Mural\Contracts\Commentable;

class Post extends Model implements Commentable
{
    use CommentableTrait;

    public function getCommentableTitleAttribute()
    {
        // TODO: Implement getCommentableTitleAttribute() method.
    }

    public function getCommentablePermalinkAttribute()
    {
        // TODO: Implement getCommentablePermalinkAttribute() method.
    }

}

Penambahan CommentableTrait otomatis akan menjadikan model Post memiliki relasi morphMany terhadap Laravolt\Mural\Comment. Karena ini relasi eloquent biasa, maka Anda bisa melakukan hal-hal berikut ini:, (*10)

// mendapatkan semua komentar
Post::find(1)->comments;

// melakukan paginasi komentar
Post::find(1)->comments()->paginate();

// atau aksi apapun, sama seperti relasi Eloquent biasa
Post::find(1)->comments()->orderBy('created_at', 'desc');

Untuk model yang ditunjuk sebagai komentator, tambahkan interface Commentator., (*11)

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravolt\Mural\Contracts\Commentator;

class User extends Authenticatable implements Commentator
{
    ...

    public function getCommentatorNameAttribute()
    {
        // return atribut nama
    }

    public function getCommentatorAvatarAttribute()
    {
        // return atribut link avatar
    }

    public function getCommentatorPermalinkAttribute()
    {
        // return atribut link ke detail user
    }

    public function canModerateComment()
    {
        // return boolean
    }
}

Shortcut

Menampilkan Widget Komentar

Untuk menampilkan widget komentar, seperti yang biasa ditemui di kebanyakan blog, tambahkan kode berikut di view Anda:, (*12)

$post = App\Models\Post::find(1);
{!! Mural::render($post, 'sample-room') !!}

Selesai, laravolt/mural sudah dilengkapi dengan Model, Controller, dan View yang siap pakai, hasilnya seperti dibawah ini:, (*13)

, (*14)

Anda juga bisa mengelompokkan komentar berdasar room tertentu, sehingga untuk satu konten bisa memiliki banyak kelompok komentar., (*15)

{!! Mural::render($post, 'collaborator') !!}
{!! Mural::render($post, 'you-can-put-anything-here') !!}

// readonly, user tidak bisa submit komentar
{!! Mural::render($post, 'room', ['readonly' => true]) !!}

Untuk masalah tampilan, saat ini skin yang didukung adalah semantic-ui. Bootstrap segera menyusul (yang berminat bisa kirim Pull Request)., (*16)

Menambah Komentar

Mural::addComment($post, 'komentar lagi', 'collaborator'); // room = collaborator

Mendapatkan Komentar

Mural::getComments($post, 'room', []);

Event

Nama event Kapan dipanggil Parameter
mural.render Ketika widget mural ditampilkan di view $content
mural.comment.add Ketika ada komentar baru $comment, $content, $user, $room
mural.comment.remove Ketika suatu komentar dihapus $comment, $user

Configuration

``` php <?php, (*17)

return [ // semantic-ui or bootstrap 'skin' => 'semantic-ui',, (*18)

// comment per page
'per_page'            => 5,

// whether user enable to vote comment or not
'vote'                => false,

// default commentable class (deprecated)
'default_commentable' => \App\Models\Post::class,

// default model for user commentator
'default_commentator' => config('auth.providers.users.model')

'middleware'   => ['web']

];, (*19)


## Testing Karena sepertinya akibat package Orchestral/testbench, `phpunit` harus dijalankan dari lokal vendor, tidak bisa dari global `phpunit`

vendor/phpunit/phpunit/phpunit, (*20)


## Roadmap * Basic comment stream (done) * Multi room (done) * Skin: semantic-ui (done) * Skin: bootstrap * Validasi komentar * Translasi (done) * Permalink untuk komentar tertentu * Realtime update jika ada komentar baru * Event (done) * Edit komentar * Hapus komentar (done) * Laporkan sebagai spam * Vote (like dislike) komentar (done) * Sort comment by latest or liked (done) ## Testing ``` bash phpunit

The Versions

19/06 2016

0.6

0.6.0.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

17/06 2016

dev-mural-1.x

dev-mural-1.x https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

26/05 2016

0.5

0.5.0.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

17/11 2015

0.4

0.4.0.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

27/10 2015

0.3.1

0.3.1.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

27/10 2015

0.3.0

0.3.0.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

23/10 2015

0.2.2

0.2.2.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

10/09 2015

0.1.3

0.1.3.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

09/09 2015

0.1.2

0.1.2.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

08/09 2015

0.1.1

0.1.1.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

08/09 2015

0.1.0

0.1.0.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural

19/08 2015

0.1

0.1.0.0 https://github.com/laravolt/mural

Laravel comment stream

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel comment mural