-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 23afb95
Showing
7 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Slynova | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
![Slynova](https://cloud.githubusercontent.com/assets/2793951/8206037/35841f80-14f6-11e5-8538-b378cd632d28.png) | ||
|
||
# Laravel-Commentable | ||
|
||
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://tldrlegal.com/license/mit-license) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/slynova/laravel-commentable.svg?style=flat-square)](https://packagist.org/packages/slynova/laravel-commentable) | ||
|
||
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/8d9f7ba6-6801-486f-aa04-570855860d57/big.png)](https://insight.sensiolabs.com/projects/8d9f7ba6-6801-486f-aa04-570855860d57) | ||
|
||
Laravel Commentable adds polymorphic threaded comments to Laravel 5.1 and above. | ||
|
||
This package use Nested Set pattern with [Baum](https://github.com/etrepat/baum).<br> | ||
[More information about Nested Set](http://en.wikipedia.org/wiki/Nested_set_model) | ||
|
||
# Table of Contents | ||
|
||
* [Requirements](#requirements) | ||
* [Getting Started](#getting-started) | ||
* [Example](#example) | ||
* [Change Logs](#change-logs) | ||
* [Contribution Guidelines](#contribution-guidelines) | ||
|
||
# <a name="requirements"></a>Requirements | ||
|
||
* As Laravel 5.1 require PHP 5.5.9+, we required the same version. | ||
|
||
# <a name="getting-started"></a>Getting Started | ||
|
||
1. Require the package with [Composer](https://getcomposer.org). | ||
```shell | ||
$ composer require slynova/laravel-commentable | ||
``` | ||
|
||
2. Add the package to your application service providers in `config/app.php`. | ||
```php | ||
'providers' => [ | ||
Illuminate\Foundation\Providers\ArtisanServiceProvider::class, | ||
Illuminate\Auth\AuthServiceProvider::class, | ||
... | ||
Slynova\Commentable\ServiceProvider::class, | ||
], | ||
``` | ||
|
||
3. Publish the package's migrations to your application and migrate. | ||
```shell | ||
$ php artisan vendor:publish --provider="Slynova\Commentable\ServiceProvider" --tag="migrations" | ||
$ php artisan migrate | ||
``` | ||
# <a name="example"></a>Example | ||
You can find an usage example of this package in the [laravel-commentable-example](https://github.com/Slynova-Org/laravel-commentable-example) repository. | ||
# <a name="change-logs"></a>Change Logs | ||
Nothing has been changed from the first release. | ||
# <a name="contribution-guidelines"></a>Contribution Guidelines | ||
Support follows PSR-2 PHP coding standards, and semantic versioning. | ||
Please report any issue you find in the issues page. | ||
Pull requests are welcome. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "slynova/laravel-commentable", | ||
"description": "Polymorphic threaded comments for Laravel", | ||
"keywords": ["laravel", "commentable", "comment", "threaded", "nested set"], | ||
"license": "MIT", | ||
"support": { | ||
"issues": "https://github.com/slynova-org/laravel-commentable/issues", | ||
"source": "https://github.com/slynova-org/laravel-commentable" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Romain Lanz", | ||
"homepage": "https://github.com/RomainLanz", | ||
"email": "[email protected]", | ||
"role": "Developer" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.5.9", | ||
"baum/baum": "~1.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Slynova\\Commentable\\": "src/Commentable" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php namespace Slynova\Commentable\Models; | ||
|
||
/** | ||
* Part of the Laravel-Commentable package. | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* Licensed under the MIT License. | ||
* | ||
* This source file is subject to the MIT License that is | ||
* bundled with this package in the LICENSE file. | ||
* It is also available at the following URL: http://opensource.org/licenses/MIT | ||
* | ||
* @version 1.0.0 | ||
* @author Slynova | ||
* @license MIT | ||
* @copyright (c) Slynova | ||
*/ | ||
|
||
use Baum\Node; | ||
|
||
class Comment extends Node | ||
{ | ||
/** | ||
* The attributes that are fillable via mass assignment. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = ['title', 'body']; | ||
|
||
/** | ||
* The relations to eager load on every query. | ||
* | ||
* @var array | ||
*/ | ||
protected $with = ['user']; | ||
|
||
/** | ||
* Determine if the comment has children. | ||
* | ||
* @return bool | ||
*/ | ||
public function hasChildren() | ||
{ | ||
return $this->children()->count() > 0; | ||
} | ||
|
||
/** | ||
* Get all of comment's children. | ||
* | ||
* @param array $columns | ||
* @return \Illuminate\Database\Eloquent\Collection | ||
*/ | ||
public function getChildren($columns = ['*']) | ||
{ | ||
return $this->children()->get($columns); | ||
} | ||
|
||
/** | ||
* Get all of the owning commentable models. | ||
* | ||
* @return Illuminate\Database\Eloquent\Relations\MorphTo | ||
*/ | ||
public function commentable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
/** | ||
* Get the user that creates the comment. | ||
* | ||
* @param $configKey string | ||
* @return Illuminate\Database\Eloquent\Relations\BelongsTo | ||
*/ | ||
public function user($configKey = 'auth.providers.users.model') | ||
{ | ||
return $this->belongsTo(config()->get($configKey)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php namespace Slynova\Commentable; | ||
|
||
/** | ||
* Part of the Laravel-Commentable package. | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* Licensed under the MIT License. | ||
* | ||
* This source file is subject to the MIT License that is | ||
* bundled with this package in the LICENSE file. | ||
* It is also available at the following URL: http://opensource.org/licenses/MIT | ||
* | ||
* @version 1.0.0 | ||
* @author Slynova | ||
* @license MIT | ||
* @copyright (c) Slynova | ||
*/ | ||
|
||
use Baum\Providers\BaumServiceProvider; | ||
|
||
class ServiceProvider extends \Illuminate\Support\ServiceProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Perform post-registration booting of services. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
$this->publishes([ | ||
__DIR__.'/../migrations/' => database_path('migrations'), | ||
], 'migrations'); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->app->register(BaumServiceProvider::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php namespace Slynova\Commentable\Traits; | ||
|
||
/** | ||
* Part of the Laravel-Commentable package. | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* Licensed under the MIT License. | ||
* | ||
* This source file is subject to the MIT License that is | ||
* bundled with this package in the LICENSE file. | ||
* It is also available at the following URL: http://opensource.org/licenses/MIT | ||
* | ||
* @version 1.0.0 | ||
* @author Slynova | ||
* @license MIT | ||
* @copyright (c) Slynova | ||
*/ | ||
|
||
use Slynova\Commentable\Models\Comment; | ||
|
||
trait Commentable | ||
{ | ||
/** | ||
* Get all of the model's comments. | ||
* | ||
* @return Illuminate\Database\Eloquent\Relations\MorphMany | ||
*/ | ||
public function comments() | ||
{ | ||
return $this->morphMany(Comment::class, 'commentable'); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/migrations/2015_11_06_000000_create_comments_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Part of the Laravel-ACL package. | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* Licensed under the MIT License. | ||
* | ||
* This source file is subject to the MIT License that is | ||
* bundled with this package in the LICENSE file. | ||
* It is also available at the following URL: http://opensource.org/licenses/MIT | ||
* | ||
* @version 1.0.0 | ||
* @author Slynova | ||
* @license MIT | ||
* @copyright (c) Slynova | ||
*/ | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateCommentsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('comments', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->timestamps(); | ||
|
||
$table->string('title')->nullable(); | ||
$table->text('body'); | ||
|
||
$table->integer('parent_id')->nullable(); | ||
$table->integer('lft')->nullable(); | ||
$table->integer('rgt')->nullable(); | ||
$table->integer('depth')->nullable(); | ||
|
||
$table->integer('commentable_id')->unsigned()->nullable(); | ||
$table->string('commentable_type')->nullable(); | ||
$table->integer('user_id')->unsigned(); | ||
|
||
$table->index('user_id'); | ||
$table->index('commentable_id'); | ||
$table->index('commentable_type'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('comments'); | ||
} | ||
} |