Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: vitaliyprokopov
- * Date: 9/23/17
- * Time: 1:56 PM
- */
- namespace App\Traits;
- use App\Category;
- use App\Comment;
- use App\Post;
- trait Commentable
- {
- private $type = null;
- /**
- * Scope a query to only include popular users.
- *
- * @param \Illuminate\Database\Eloquent\Builder $query
- * @return \Illuminate\Database\Eloquent\Builder
- */
- public function scopeComment($query)
- {
- if ($this instanceof Post) {
- $this->type = Comment::TYPE_POST;
- } else if ($this instanceof Category) {
- $this->type = Comment::TYPE_CATEGORY;
- }
- if ($this->type) {
- return Comment::where('target_id', $this->id)->where('target_type', $this->type)->orderBy('created_at', 'desc')->get();
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement