11<?php namespace TeachMe \Http \Controllers ;
22
3- use TeachMe \ Entities \ Ticket ;
3+ use Illuminate \ Http \ Request ;
44use TeachMe \Repositories \TicketRepository ;
55use TeachMe \Repositories \VoteRepository ;
66
@@ -18,18 +18,26 @@ public function __construct(
1818 $ this ->voteRepository = $ voteRepository ;
1919 }
2020
21- public function submit ($ id )
21+ public function submit ($ id, Request $ request )
2222 {
2323 $ ticket = $ this ->ticketRepository ->findOrFail ($ id );
24- $ this ->voteRepository ->vote (currentUser (), $ ticket );
24+ $ success = $ this ->voteRepository ->vote (currentUser (), $ ticket );
25+
26+ if ($ request ->ajax ()) {
27+ return response ()->json (compact ('success ' ));
28+ }
2529
2630 return redirect ()->back ();
2731 }
2832
29- public function destroy ($ id )
33+ public function destroy ($ id, Request $ request )
3034 {
3135 $ ticket = $ this ->ticketRepository ->findOrFail ($ id );
32- $ this ->voteRepository ->unvote (currentUser (), $ ticket );
36+ $ success = $ this ->voteRepository ->unvote (currentUser (), $ ticket );
37+
38+ if ($ request ->ajax ()) {
39+ return response ()->json (compact ('success ' ));
40+ }
3341
3442 return redirect ()->back ();
3543 }
0 commit comments