1 | <?php |
||
13 | class CommentQueryBuilder |
||
14 | { |
||
15 | protected $query = null; |
||
16 | |||
17 | public function __construct(MorphMany $query) |
||
21 | |||
22 | public function from($date) |
||
28 | |||
29 | public function to($date) |
||
35 | |||
36 | /** |
||
37 | * @param $user |
||
38 | * |
||
39 | * @return CommentQueryBuilder |
||
40 | * |
||
41 | * @throws \Throwable |
||
42 | */ |
||
43 | public function user($user) |
||
51 | |||
52 | /** |
||
53 | * @param Model $commentable |
||
54 | * |
||
55 | * @return CommentQueryBuilder |
||
56 | * |
||
57 | * @throws \Throwable |
||
58 | */ |
||
59 | public function voteable(Model $commentable) |
||
60 | { |
||
61 | throw_unless(in_array(Commentable::class, class_uses_recursive($commentable)), ModelDoesNotUseCommentableTrait::class, get_class($commentable).' does not use the Commentable Trait'); |
||
62 | |||
63 | $this->query = $this->query |
||
64 | ->leftJoin('comments', function (JoinClause $join) use ($commentable) { |
||
65 | $join |
||
66 | ->on('comments.commentable_id', $commentable->getTable() . '.id') |
||
67 | ->where('comments.commentable_type', in_array(get_class($commentable), Relation::morphMap()) ? array_search(get_class($commentable), Relation::morphMap()) : get_class($commentable)); |
||
68 | }); |
||
69 | |||
70 | return $this; |
||
71 | } |
||
72 | |||
73 | public function getQuery() |
||
77 | } |
||
78 |