File tree Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Expand file tree Collapse file tree 2 files changed +27
-7
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace TeachMe \Repositories ;
4+
5+ abstract class BaseRepository {
6+
7+ /**
8+ * @return \TeachMe\Entities\Entity
9+ */
10+ abstract public function getModel ();
11+
12+ /**
13+ * @return \Illuminate\Database\Eloquent\Builder
14+ */
15+ public function newQuery ()
16+ {
17+ return $ this ->getModel ()->newQuery ();
18+ }
19+
20+ public function findOrFail ($ id )
21+ {
22+ return $ this ->newQuery ()->findOrFail ($ id );
23+ }
24+
25+ }
Original file line number Diff line number Diff line change 44
55use TeachMe \Entities \Ticket ;
66
7- class TicketRepository {
7+ class TicketRepository extends BaseRepository {
88
99 public function getModel ()
1010 {
@@ -13,7 +13,7 @@ public function getModel()
1313
1414 protected function selectTicketsList ()
1515 {
16- return Ticket:: selectRaw (
16+ return $ this -> newQuery ()-> selectRaw (
1717 'tickets.*, '
1818 . '( SELECT COUNT(*) FROM ticket_comments WHERE ticket_comments.ticket_id = tickets.id ) as num_comments, '
1919 . '( SELECT COUNT(*) FROM ticket_votes WHERE ticket_votes.ticket_id = tickets.id ) as num_votes '
@@ -43,9 +43,4 @@ public function paginateClosed()
4343 ->paginate (20 );
4444 }
4545
46- public function findOrFail ($ id )
47- {
48- return Ticket::findOrFail ($ id );
49- }
50-
5146}
You can’t perform that action at this time.
0 commit comments