├── LICENSE.txt
├── README.md
├── composer.json
└── src
├── Commentable
├── Models
│ └── Comment.php
├── ServiceProvider.php
└── Traits
│ └── Commentable.php
└── migrations
└── 2015_11_06_000000_create_comments_table.php
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Slynova
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel-Commentable
2 |
3 | [](https://tldrlegal.com/license/mit-license)
4 | [](https://packagist.org/packages/thyagobrejao/laravel-commentable)
5 |
6 | Laravel Commentable adds polymorphic threaded comments to Laravel 5.1 and above. (based on dead slynova/laravel-commentable)
7 |
8 | This package use Nested Set pattern with [Baum](https://github.com/etrepat/baum).
9 | [More information about Nested Set](http://en.wikipedia.org/wiki/Nested_set_model)
10 |
11 | # Table of Contents
12 |
13 | * [Requirements](#requirements)
14 | * [Getting Started](#getting-started)
15 | * [Example](#example)
16 | * [Change Logs](#change-logs)
17 | * [Contribution Guidelines](#contribution-guidelines)
18 |
19 | # Requirements
20 |
21 | * As Laravel 5.1 require PHP 5.5.9+, we required the same version.
22 |
23 | # Getting Started
24 |
25 | 1. Require the package with [Composer](https://getcomposer.org).
26 | ```shell
27 | $ composer require thyagobrejao/laravel-commentable
28 | ```
29 |
30 | 2. Add the package to your application service providers in `config/app.php`.
31 | ```php
32 | 'providers' => [
33 |
34 | Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
35 | Illuminate\Auth\AuthServiceProvider::class,
36 | ...
37 | ThyagoBrejao\Commentable\ServiceProvider::class,
38 |
39 | ],
40 | ```
41 |
42 | 3. Publish the package's migrations to your application and migrate.
43 | ```shell
44 | $ php artisan vendor:publish --provider="ThyagoBrejao\Commentable\ServiceProvider" --tag="migrations"
45 | $ php artisan migrate
46 | ```
47 |
48 | # Example
49 |
50 | TODO
51 | # Change Logs
52 |
53 | Nothing has been changed from the first release.
54 |
55 | # Contribution Guidelines
56 |
57 | Support follows PSR-2 PHP coding standards, and semantic versioning.
58 |
59 | Please report any issue you find in the issues page.
60 | Pull requests are welcome.
61 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "thyagobrejao/laravel-commentable",
3 | "description": "Polymorphic threaded comments for Laravel",
4 | "keywords": ["laravel", "commentable", "comment", "threaded", "nested set"],
5 | "license": "MIT",
6 | "support": {
7 | "issues": "https://github.com/thyagobrejao/laravel-commentable/issues",
8 | "source": "https://github.com/thyagobrejao/laravel-commentable"
9 | },
10 | "authors": [
11 | {
12 | "name": "Thyago Assunção",
13 | "homepage": "https://github.com/thyagobrejao",
14 | "email": "thyago.brejao@gmail.com",
15 | "role": "Developer"
16 | }
17 | ],
18 | "require": {
19 | "php": ">=5.5.9",
20 | "baum/baum": "~1.1"
21 | },
22 | "autoload": {
23 | "psr-4": {
24 | "ThyagoBrejao\\Commentable\\": "src/Commentable"
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Commentable/Models/Comment.php:
--------------------------------------------------------------------------------
1 | children()->count() > 0;
46 | }
47 |
48 | /**
49 | * Get all of comment's children.
50 | *
51 | * @param array $columns
52 | * @return \Illuminate\Database\Eloquent\Collection
53 | */
54 | public function getChildren($columns = ['*'])
55 | {
56 | return $this->children()->get($columns);
57 | }
58 |
59 | /**
60 | * Get all of the owning commentable models.
61 | *
62 | * @return Illuminate\Database\Eloquent\Relations\MorphTo
63 | */
64 | public function commentable()
65 | {
66 | return $this->morphTo();
67 | }
68 |
69 | /**
70 | * Get the user that creates the comment.
71 | *
72 | * @param $configKey string
73 | * @return Illuminate\Database\Eloquent\Relations\BelongsTo
74 | */
75 | public function user($configKey = 'auth.providers.users.model')
76 | {
77 | return $this->belongsTo(config()->get($configKey));
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/Commentable/ServiceProvider.php:
--------------------------------------------------------------------------------
1 | publishes([
39 | __DIR__.'/../migrations/' => database_path('migrations'),
40 | ], 'migrations');
41 | }
42 |
43 | /**
44 | * Register the service provider.
45 | *
46 | * @return void
47 | */
48 | public function register()
49 | {
50 | $this->app->register(BaumServiceProvider::class);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Commentable/Traits/Commentable.php:
--------------------------------------------------------------------------------
1 | morphMany(Comment::class, 'commentable');
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/migrations/2015_11_06_000000_create_comments_table.php:
--------------------------------------------------------------------------------
1 | increments('id');
34 | $table->timestamps();
35 |
36 | $table->string('title')->nullable();
37 | $table->text('body');
38 |
39 | $table->integer('parent_id')->nullable();
40 | $table->integer('lft')->nullable();
41 | $table->integer('rgt')->nullable();
42 | $table->integer('depth')->nullable();
43 |
44 | $table->integer('commentable_id')->unsigned()->nullable();
45 | $table->string('commentable_type')->nullable();
46 | $table->integer('user_id')->unsigned();
47 |
48 | $table->index('user_id');
49 | $table->index('commentable_id');
50 | $table->index('commentable_type');
51 | });
52 | }
53 |
54 | /**
55 | * Reverse the migrations.
56 | *
57 | * @return void
58 | */
59 | public function down()
60 | {
61 | Schema::drop('comments');
62 | }
63 | }
64 |
--------------------------------------------------------------------------------