Skip to content

Commit

Permalink
change user model to Authenticatable contract
Browse files Browse the repository at this point in the history
  • Loading branch information
MoamenEltouny committed Aug 6, 2022
1 parent 314f2ee commit 7312981
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 64 deletions.
20 changes: 10 additions & 10 deletions src/Traits/Actions/Bookmark/isBookmarkable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Bookmark;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Bookmark;

trait isBookmarkable
{
/**
* Get Bookmark Object
*
* @param Model $bookmarker
* @param Authenticatable $bookmarker
* @return Bookmark|null
*/
public function getBookmark(Model $bookmarker)
public function getBookmark(Authenticatable $bookmarker)
{
return $this->bookmarks()->where(['bookmarker_id' => $bookmarker->getKey(), 'bookmarker_type' => get_class($bookmarker)])->first();
}

/**
* Bookmark with a Model
*
* @param Model $bookmarker
* @param Authenticatable $bookmarker
* @param array|null $data
* @return boolean
*/
public function bookmarkBy(Model $bookmarker, array $data = null)
public function bookmarkBy(Authenticatable $bookmarker, array $data = null)
{
if ($bookmark = $this->getBookmark($bookmarker)) {
return $bookmark->update(['data' => $data]);
Expand All @@ -35,12 +35,12 @@ public function bookmarkBy(Model $bookmarker, array $data = null)
}

/**
* Unbookmark with a Model
* Un-bookmark with a Model
*
* @param Model $bookmarker
* @param Authenticatable $bookmarker
* @return boolean
*/
public function unBookmarkBy(Model $bookmarker)
public function unBookmarkBy(Authenticatable $bookmarker)
{
if ($bookmark = $this->getBookmark($bookmarker))
return $bookmark->delete();
Expand All @@ -51,10 +51,10 @@ public function unBookmarkBy(Model $bookmarker)
/**
* Has Bookmarked By Bookmarker
*
* @param Model $bookmarker
* @param Authenticatable $bookmarker
* @return boolean
*/
public function bookmarkedBy(Model $bookmarker)
public function bookmarkedBy(Authenticatable $bookmarker)
{
return $this->bookmarks()->where(['bookmarker_id' => $bookmarker->getKey(), 'bookmarker_type' => get_class($bookmarker)])->exists();
}
Expand Down
10 changes: 5 additions & 5 deletions src/Traits/Actions/Comment/isCommentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Comment;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Comment;

trait isCommentable
{
/**
* Comment with a Model
*
* @param Model $commenter
* @param Authenticatable $commenter
* @param string $comment
* @return boolean
*/
public function commentBy(Model $commenter, string $body)
public function commentBy(Authenticatable $commenter, string $body)
{
return $this->comments()->make(['commentable' => $this, 'comment' => $body])->commenter()->associate($commenter)->save();
}

/**
* Has Commented By Commenter
*
* @param Model $commenter
* @param Authenticatable $commenter
* @return boolean
*/
public function commentedBy(Model $commenter)
public function commentedBy(Authenticatable $commenter)
{
return $this->comments()->where(['commenter_id' => $commenter->getKey(), 'commenter_type' => get_class($commenter)])->exists();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Traits/Actions/Favourite/isFavourable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Favourite;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Favourite;

trait isFavourable
{
/**
* Favourite with a Model
*
* @param Model $favorer
* @param Authenticatable $favorer
* @return boolean
*/
public function favouriteBy(Model $favorer)
public function favouriteBy(Authenticatable $favorer)
{
if ($this->favouredBy($favorer))
return true;
Expand All @@ -24,10 +24,10 @@ public function favouriteBy(Model $favorer)
/**
* Unfavourite with a Model
*
* @param Model $favorer
* @param Authenticatable $favorer
* @return boolean
*/
public function unFavouriteBy(Model $favorer)
public function unFavouriteBy(Authenticatable $favorer)
{
if ($favourite = $this->favourites()->where(['favorer_id' => $favorer->getKey(), 'favorer_type' => get_class($favorer)])->first())
return $favourite->delete();
Expand All @@ -38,10 +38,10 @@ public function unFavouriteBy(Model $favorer)
/**
* Has Favoured By favour
*
* @param Model $favorer
* @param Authenticatable $favorer
* @return boolean
*/
public function favouredBy(Model $favorer)
public function favouredBy(Authenticatable $favorer)
{
return $this->favourites()->where(['favorer_id' => $favorer->getKey(), 'favorer_type' => get_class($favorer)])->exists();
}
Expand Down
16 changes: 8 additions & 8 deletions src/Traits/Actions/Follow/isFollowable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Follow;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Follow;

trait isFollowable
{
/**
* Follow with a Model
*
* @param Model follower
* @param Authenticatable follower
* @return boolean
*/
public function followBy(Model $follower)
public function followBy(Authenticatable $follower)
{
if ($this->followedBy($follower))
return true;
Expand All @@ -22,12 +22,12 @@ public function followBy(Model $follower)
}

/**
* Unfollow with a Model
* Un-follow with a Model
*
* @param Model follower
* @param Authenticatable follower
* @return boolean
*/
public function unFollowBy(Model $follower)
public function unFollowBy(Authenticatable $follower)
{
if ($follow = $this->follows()->where(['follower_id' => $follower->getKey(), 'follower_type' => get_class($follower)])->first())
return $follow->delete();
Expand All @@ -38,10 +38,10 @@ public function unFollowBy(Model $follower)
/**
* Has Followed By Follower
*
* @param Model follower
* @param Authenticatable follower
* @return boolean
*/
public function followedBy(Model $follower)
public function followedBy(Authenticatable $follower)
{
return $this->follows()->where(['follower_id' => $follower->getKey(), 'follower_type' => get_class($follower)])->exists();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Traits/Actions/Like/isLikeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Like;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Like;

trait isLikeable
{
/**
* Like with a Model
*
* @param Model $liker
* @param Authenticatable $liker
* @return boolean
*/
public function likeBy(Model $liker)
public function likeBy(Authenticatable $liker)
{
if ($this->likedBy($liker))
return true;
Expand All @@ -24,10 +24,10 @@ public function likeBy(Model $liker)
/**
* Unlike with a Model
*
* @param Model $liker
* @param Authenticatable $liker
* @return boolean
*/
public function unLikeBy(Model $liker)
public function unLikeBy(Authenticatable $liker)
{
if ($like = $this->likes()->where(['liker_id' => $liker->getKey(), 'liker_type' => get_class($liker)])->first())
return $like->delete();
Expand All @@ -38,10 +38,10 @@ public function unLikeBy(Model $liker)
/**
* Has Liked By Liker
*
* @param Model $liker
* @param Authenticatable $liker
* @return boolean
*/
public function likedBy(Model $liker)
public function likedBy(Authenticatable $liker)
{
return $this->likes()->where(['liker_id' => $liker->getKey(), 'liker_type' => get_class($liker)])->exists();
}
Expand Down
18 changes: 9 additions & 9 deletions src/Traits/Actions/Review/isReviewable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Review;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Review;

trait isReviewable
{
/**
* Get Review Object
*
* @param Model $reviewer
* @param Authenticatable $reviewer
* @return Vote|null
*/
public function getReview(Model $reviewer)
public function getReview(Authenticatable $reviewer)
{
return $this->reviews()->where(['reviewer_id' => $reviewer->getKey(), 'reviewer_type' => get_class($reviewer)])->first();
}

/**
* Review Model By reviewer
*
* @param Model $reviewer
* @param Authenticatable $reviewer
* @param float $rate
* @param string|null $comment
* @return boolean
*/
public function reviewBy(Model $reviewer, float $rate = 0, string $comment = null)
public function reviewBy(Authenticatable $reviewer, float $rate = 0, string $comment = null)
{
if ($review = $this->getReview($reviewer)) {
return $review->update([
Expand All @@ -45,10 +45,10 @@ public function reviewBy(Model $reviewer, float $rate = 0, string $comment = nul
/**
* UnReview Model By reviewer
*
* @param Model $reviewer
* @param Authenticatable $reviewer
* @return boolean
*/
public function unReviewBy(Model $reviewer)
public function unReviewBy(Authenticatable $reviewer)
{
if ($review = $this->getReview($reviewer))
return $review->delete();
Expand All @@ -59,10 +59,10 @@ public function unReviewBy(Model $reviewer)
/**
* Has Reviewed By reviewer
*
* @param Model $reviewer
* @param Authenticatable $reviewer
* @return boolean
*/
public function reviewedBy(Model $reviewer)
public function reviewedBy(Authenticatable $reviewer)
{
return $this->reviews()->where(['reviewer_id' => $reviewer->getKey(), 'reviewer_type' => get_class($reviewer)])->exists();
}
Expand Down
14 changes: 7 additions & 7 deletions src/Traits/Actions/Subscribe/isSubscribable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace Pharaonic\Laravel\Users\Traits\Actions\Subscribe;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable;
use Pharaonic\Laravel\Users\Models\Actions\Subscribe;

trait isSubscribable
{
/**
* Subscribe with a Model
*
* @param Model $subscriber
* @param Authenticatable $subscriber
* @return boolean
*/
public function subscribeBy(Model $subscriber)
public function subscribeBy(Authenticatable $subscriber)
{
if ($this->subscribedBy($subscriber))
return true;
Expand All @@ -24,10 +24,10 @@ public function subscribeBy(Model $subscriber)
/**
* Unsubscribe with a Model
*
* @param Model $subscriber
* @param Authenticatable $subscriber
* @return boolean
*/
public function unSubscribeBy(Model $subscriber)
public function unSubscribeBy(Authenticatable $subscriber)
{
if ($subscription = $this->subscriptions()->where(['subscriber_id' => $subscriber->getKey(), 'subscriber_type' => get_class($subscriber)])->first())
return $subscription->delete();
Expand All @@ -38,10 +38,10 @@ public function unSubscribeBy(Model $subscriber)
/**
* Has Subscribed By Subscriber
*
* @param Model $subscriber
* @param Authenticatable $subscriber
* @return boolean
*/
public function subscribedBy(Model $subscriber)
public function subscribedBy(Authenticatable $subscriber)
{
return $this->subscriptions()->where(['subscriber_id' => $subscriber->getKey(), 'subscriber_type' => get_class($subscriber)])->exists();
}
Expand Down
Loading

0 comments on commit 7312981

Please sign in to comment.