|
6 | 6 | use Illuminate\Http\Request; |
7 | 7 | use TeachMe\Entities\Ticket; |
8 | 8 | use TeachMe\Entities\TicketComment; |
| 9 | +use TeachMe\Repositories\CommentRepository; |
| 10 | +use TeachMe\Repositories\TicketRepository; |
9 | 11 |
|
10 | 12 | class CommentsController extends Controller { |
11 | 13 |
|
| 14 | + protected $commentRepository; |
| 15 | + protected $ticketRepository; |
| 16 | + |
| 17 | + public function __construct( |
| 18 | + TicketRepository $ticketRepository, |
| 19 | + CommentRepository $commentRepository |
| 20 | + ) |
| 21 | + { |
| 22 | + $this->commentRepository = $commentRepository; |
| 23 | + $this->ticketRepository = $ticketRepository; |
| 24 | + } |
| 25 | + |
12 | 26 | public function submit($id, Request $request, Guard $auth) |
13 | 27 | { |
14 | 28 | $this->validate($request, [ |
15 | 29 | 'comment' => 'required|max:250', |
16 | 30 | 'link' => 'url' |
17 | 31 | ]); |
18 | 32 |
|
19 | | - $comment = new TicketComment($request->only(['comment', 'link'])); |
20 | | - $comment->user_id = $auth->id(); |
| 33 | + $ticket = $this->ticketRepository->findOrFail($id); |
21 | 34 |
|
22 | | - $ticket = Ticket::findOrFail($id); |
23 | | - $ticket->comments()->save($comment); |
| 35 | + $this->commentRepository->create( |
| 36 | + $ticket, |
| 37 | + currentUser(), |
| 38 | + $request->get('comment'), |
| 39 | + $request->get('link') |
| 40 | + ); |
24 | 41 |
|
25 | 42 | session()->flash('success', 'Tu comentario fue guardado exitosamente'); |
26 | 43 | return redirect()->back(); |
|
0 commit comments