Skip to content

Commit

Permalink
Merge pull request #46 from sulaiman1000/master
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Mar 18, 2024
2 parents 718c978 + 06f3378 commit a1cfcc9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions config/favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@
* Model name for favorite record.
*/
'favorite_model' => Overtrue\LaravelFavorite\Favorite::class,

/*
* Model name for favoriter model.
*/
'favoriter_model' => App\Models\User::class,
];
2 changes: 1 addition & 1 deletion src/Favorite.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function favoriteable(): \Illuminate\Database\Eloquent\Relations\MorphTo

public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(\config('auth.providers.users.model'), \config('favorite.user_foreign_key'));
return $this->belongsTo(\config('favorite.favoriter_model'), \config('favorite.user_foreign_key'));
}

public function favoriter(): \Illuminate\Database\Eloquent\Relations\BelongsTo
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Favoriteable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function hasFavoriter(Model $user): bool

public function hasBeenFavoritedBy(Model $user): bool
{
if (! \is_a($user, config('auth.providers.users.model'))) {
if (! \is_a($user, config('favorite.favoriter_model'))) {
return false;
}

Expand All @@ -45,7 +45,7 @@ public function favorites(): \Illuminate\Database\Eloquent\Relations\MorphMany
public function favoriters(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(
config('auth.providers.users.model'),
config('favorite.favoriter_model'),
config('favorite.favorites_table'),
'favoriteable_id',
config('favorite.user_foreign_key')
Expand Down
2 changes: 1 addition & 1 deletion tests/FeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function setUp(): void

Event::fake();

config(['auth.providers.users.model' => User::class]);
config(['favorite.favoriter_model' => User::class]);
}

public function test_basic_features()
Expand Down

0 comments on commit a1cfcc9

Please sign in to comment.