File tree Expand file tree Collapse file tree 9 files changed +68
-35
lines changed Expand file tree Collapse file tree 9 files changed +68
-35
lines changed Original file line number Diff line number Diff line change 11<?php
2- /**
3- * Created by PhpStorm.
4- * User: bobbyborisov
5- * Date: 12/3/17
6- * Time: 1:51 PM
7- */
82
93namespace App \Helpers ;
104
@@ -27,7 +21,7 @@ public function likedBy(User $user)
2721
2822 public function dislikedBy (User $ user )
2923 {
30- $ this ->likes ()->where ('user_id ' , $ user ->id )->get ()->first ()->delete ();
24+ optional ( $ this ->likes ()->where ('user_id ' , $ user ->id )->get ()->first () )->delete ();
3125 }
3226
3327 public function likes ()
@@ -37,6 +31,7 @@ public function likes()
3731
3832 public function isLikedBy (User $ user )
3933 {
34+ if ($ user == null ) return false ;
4035 return $ this ->likes ()->where ('user_id ' , $ user ->id )->exists ();
4136 }
4237
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ require('./bootstrap');
1616$ ( 'select.selectize' ) . selectize ( { maxItems : 3 } ) ;
1717$ ( 'textarea.wysiwyg' ) . markdown ( { iconlibrary : 'fa' } ) ;
1818
19- // const app = new Vue({
20- // el: '#app'
21- // });
19+ Vue . component ( 'like' , require ( './components/Like.vue' ) ) ;
20+
21+ const app = new Vue ( {
22+ el : '#app'
23+ } ) ;
Original file line number Diff line number Diff line change 1+ <template >
2+ <div >
3+ <span style =" margin-right :3px " >{{count}}</span ><i class =" fa" :class =" classes" @click =" toggle" ></i >
4+ </div >
5+ </template >
6+
7+ <script >
8+ export default {
9+ data (){
10+ return {
11+ count: 0 ,
12+ isLiked: false
13+ }
14+ },
15+ computed: {
16+ classes (){
17+ return this .isLiked ? ' fa-thumbs-down text-danger' : ' fa-thumbs-up text-success' ;
18+ }
19+ },
20+ methods: {
21+ toggle (){
22+ return this .isLiked ? this .dislike () : this .like ();
23+ },
24+ like (){
25+ // axios call
26+ console .log (' like' );
27+ this .count ++ ;
28+ this .isLiked = true ;
29+ },
30+ dislike (){
31+ // axios call
32+ console .log (' dislike' );
33+ this .count -- ;
34+ this .isLiked = false ;
35+ }
36+ }
37+ }
38+ </script >
Original file line number Diff line number Diff line change 7171 <a class =" btn btn-danger btn-xs" href =" #" data-toggle =" modal" data-target =" #deleteReply{{ $reply -> id () } }" >Delete</a >
7272 </div >
7373 @endcan
74+ @auth
7475 <div class =" thread-info-likes" >
75- @if (! $reply -> isLikedBy (auth ()-> user ()) )
76- {{ Form:: open ([' route' => [' replies.like' , $reply ], ' method' => ' PUT' ]) } }
77- <span >{{ $reply -> likes_count } } </span >
78- {{ Form:: submit (' like' , [' class' => ' btn btn-xs btn-success' ]) } }
79- {{ Form:: close () } }
80- @else
81- {{ Form:: open ([' route' => [' replies.dislike' , $reply ], ' method' => ' DELETE ' ]) } }
82- <span >{{ $reply -> likes_count } } </span >
83- {{ Form:: submit (' dislike' , [' class' => ' btn btn-xs btn-danger' ]) } }
84- {{ Form:: close () } }
85- @endif
76+ <like ></like >
8677 </div >
78+ @endauth
8779 </div >
8880
8981 <div class =" panel-body forum-content" >
Original file line number Diff line number Diff line change 11@extends (' layouts.base' )
22
33@section (' body' )
4- <div class =" container" >
4+ <div id = " app " class =" container" >
55 @include (' layouts._alerts' )
66
77 @yield (' content' )
Original file line number Diff line number Diff line change @@ -16,11 +16,12 @@ class DeleteThreadTest extends TestCase
1616 public function we_can_delete_a_thread_and_its_replies ()
1717 {
1818 $ thread = factory (Thread::class)->create ();
19- factory (Reply::class)->create (['replyable_id ' => $ thread ->id ()]);
19+ $ reply = factory (Reply::class)->create (['replyable_id ' => $ thread ->id ()]);
2020
2121 $ this ->dispatch (new DeleteThread ($ thread ));
2222
2323 $ this ->assertDatabaseMissing ('threads ' , ['id ' => $ thread ->id ()]);
2424 $ this ->assertDatabaseMissing ('replies ' , ['replyable_id ' => $ thread ->id ()]);
25+ $ this ->assertDatabaseMissing ('likes ' , ['liked_type ' => get_class ($ reply ), 'liked_id ' => $ reply ->id ()]);
2526 }
2627}
Original file line number Diff line number Diff line change @@ -25,4 +25,20 @@ public function we_can_dislike_a_reply()
2525
2626 $ this ->assertFalse ($ reply ->fresh ()->isLikedBy ($ user ));
2727 }
28+
29+ /** @test */
30+ public function we_cannot_dislike_a_reply ()
31+ {
32+ $ user = factory (User::class)->create ();
33+ $ reply = factory (Reply::class)->create ();
34+
35+ $ reply ->likedBy ($ user );
36+ $ this ->assertTrue ($ reply ->fresh ()->isLikedBy ($ user ));
37+
38+ $ this ->dispatch (new DislikeReply ($ reply , $ user ));
39+
40+ $ this ->dispatch (new DislikeReply ($ reply , $ user ));
41+
42+ //$this->assertFalse($reply->fresh()->isLikedBy($user));
43+ }
2844}
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public function we_cannot_like_a_reply_twice()
3535 $ this ->assertTrue ($ reply ->fresh ()->isLikedBy ($ user ));
3636
3737 $ this ->expectException (CannotLikeReplyTwice::class);
38+
3839 $ this ->dispatch (new LikeReply ($ reply , $ user ));
3940 }
4041}
Original file line number Diff line number Diff line change @@ -78,16 +78,4 @@ public function users_cannot_mark_a_reply_as_the_solution_of_the_thread_if_they_
7878 $ this ->put ('/forum/the-first-thread/mark-solution/ ' .$ reply ->id ())
7979 ->assertForbidden ();
8080 }
81-
82- /** @test */
83- public function user_can_like_a_reply ()
84- {
85- $ user = factory (User::class)->create ();
86-
87- $ thread = factory (Thread::class)->create (['author_id ' => $ user ->id (), 'slug ' => 'the-first-thread ' ]);
88- $ reply = factory (Reply::class)->create (['replyable_id ' => $ thread ->id ()]);
89-
90- $ this ->put ('/forum/the-first-thread/ ' .$ reply ->id ().'/like ' );
91- //->assertForbidden();
92- }
9381}
You can’t perform that action at this time.
0 commit comments