File tree Expand file tree Collapse file tree 5 files changed +27
-23
lines changed
Expand file tree Collapse file tree 5 files changed +27
-23
lines changed Original file line number Diff line number Diff line change @@ -12,13 +12,13 @@ Trait for Laravel Eloquent models to allow easy implementation of a "like" or "f
1212
1313#### Composer Install (for Laravel 5)
1414
15- composer require rtconner/laravel-likeable "~1.0.7 "
15+ composer require rtconner/laravel-likeable "~1.0"
1616
1717#### Install and then run the migrations
1818
1919``` php
2020'providers' => array(
21- ' Conner\Likeable\LikeableServiceProvider' ,
21+ Conner\Likeable\LikeableServiceProvider::class ,
2222);
2323```
2424
Original file line number Diff line number Diff line change 1- <?php namespace Conner \ Likeable ;
1+ <?php
22
3- use Illuminate \ Database \ Eloquent \ Model as Eloquent ;
3+ namespace Conner \ Likeable ;
44
5- class Like extends Eloquent {
5+ use Illuminate \ Database \ Eloquent \ Model as Eloquent ;
66
7+ class Like extends Eloquent
8+ {
79 protected $ table = 'likeable_likes ' ;
810 public $ timestamps = true ;
911 protected $ fillable = ['likable_id ' , 'likable_type ' , 'user_id ' ];
Original file line number Diff line number Diff line change 1- <?php namespace Conner \ Likeable ;
1+ <?php
22
3- use Illuminate \ Database \ Eloquent \ Model as Eloquent ;
3+ namespace Conner \ Likeable ;
44
5- class LikeCounter extends Eloquent {
5+ use Illuminate \ Database \ Eloquent \ Model as Eloquent ;
66
7+ class LikeCounter extends Eloquent
8+ {
79 protected $ table = 'likeable_like_counters ' ;
810 public $ timestamps = false ;
911 protected $ fillable = ['likable_id ' , 'likable_type ' , 'count ' ];
Original file line number Diff line number Diff line change 1- <?php namespace Conner \Likeable ;
1+ <?php
2+
3+ namespace Conner \Likeable ;
24
35use Illuminate \Support \ServiceProvider ;
46
57/**
68 * Copyright (C) 2015 Robert Conner
79 */
8- class LikeableServiceProvider extends ServiceProvider {
9-
10+ class LikeableServiceProvider extends ServiceProvider
11+ {
1012 protected $ defer = true ;
1113
12- public function boot () {
14+ public function boot ()
15+ {
1316 $ this ->publishes ([
14- __DIR__ .'/../migrations/2014_09_10_065447_create_likeable_tables.php ' => database_path ( ' migrations/2014_09_10_065447_create_likeable_tables.php ') ,
17+ __DIR__ .'/../migrations/2014_09_10_065447_create_likeable_tables.php ' => $ this -> app -> databasePath (). ' / migrations/2014_09_10_065447_create_likeable_tables.php ' ,
1518 ]);
1619 }
1720
1821 public function register () {}
1922
20- public function when () {
23+ public function when ()
24+ {
2125 return array ('artisan.start ' );
2226 }
23-
2427}
Original file line number Diff line number Diff line change 1- <?php namespace Conner \Likeable ;
1+ <?php
2+
3+ namespace Conner \Likeable ;
24
35/**
46 * Copyright (C) 2014 Robert Conner
57 */
6-
7- trait LikeableTrait {
8-
8+ trait LikeableTrait
9+ {
910 /**
1011 * Fetch only records that currently logged in user has liked/followed
1112 */
@@ -118,16 +119,12 @@ private function incrementLikeCount()
118119 $ counter = $ this ->likeCounter ()->first ();
119120
120121 if ($ counter ) {
121-
122122 $ counter ->count ++;
123123 $ counter ->save ();
124-
125124 } else {
126-
127125 $ counter = new LikeCounter ;
128126 $ counter ->count = 1 ;
129127 $ this ->likeCounter ()->save ($ counter );
130-
131128 }
132129 }
133130
You can’t perform that action at this time.
0 commit comments