Giter Site home page Giter Site logo

laravel-favorite's Introduction

Laravel Favorite

❤️ User favorite feature for Laravel Application.

CI Latest Stable Version Latest Unstable Version Total Downloads License

Sponsor me

Installing

composer require overtrue/laravel-favorite -vvv

Configuration & Migrations

php artisan vendor:publish --provider="Overtrue\LaravelFavorite\FavoriteServiceProvider"

Usage

Traits

Overtrue\LaravelFavorite\Traits\Favoriter

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Overtrue\LaravelFavorite\Traits\Favoriter;

class User extends Authenticatable
{
    use Favoriter;

    <...>
}

Overtrue\LaravelFavorite\Traits\Favoriteable

use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelFavorite\Traits\Favoriteable;

class Post extends Model
{
    use Favoriteable;

    <...>
}

API

$user = User::find(1);
$post = Post::find(2);

$user->favorite($post);
$user->unfavorite($post);
$user->toggleFavorite($post);
$user->getFavoriteItems(Post::class)

$user->hasFavorited($post);
$post->hasBeenFavoritedBy($user);

Get object favoriters:

foreach($post->favoriters as $user) {
    // echo $user->name;
}

Get Favorite Model from User.

Used Favoriter Trait Model can easy to get Favoriteable Models to do what you want. _note: this method will return a Illuminate\Database\Eloquent\Builder _

$user->getFavoriteItems(Post::class);

// Do more
$favoritePosts = $user->getFavoriteItems(Post::class)->get();
$favoritePosts = $user->getFavoriteItems(Post::class)->paginate();
$favoritePosts = $user->getFavoriteItems(Post::class)->where('title', 'Laravel-Favorite')->get();

Aggregations

// all
$user->favorites()->count();

// with type
$user->favorites()->withType(Post::class)->count();

// favoriters count
$post->favoriters()->count();

List with *_count attribute:

$users = User::withCount('favorites')->get();

foreach($users as $user) {
    echo $user->favorites_count;
}


// for Favoriteable models:
$posts = Post::withCount('favoriters')->get();

foreach($posts as $post) {
    echo $post->favorites_count;
}

Attach user favorite status to favoriteable collection

You can use Favoriter::attachFavoriteStatus($favoriteables) to attach the user favorite status, it will set has_favorited attribute to each model of $favoriteables:

For model

$post = Post::find(1);

$post = $user->attachFavoriteStatus($post);

// result
[
    "id" => 1
    "title" => "Add socialite login support."
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_favorited" => true
 ],

For Collection | Paginator | CursorPaginator | array:

$posts = Post::oldest('id')->get();

$posts = $user->attachFavoriteStatus($posts);

$posts = $posts->toArray();

// result
[
  [
    "id" => 1
    "title" => "Post title1"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_favorited" => true
  ],
  [
    "id" => 2
    "title" => "Post title2"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_favorited" => false
  ],
  [
    "id" => 3
    "title" => "Post title3"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_favorited" => true
  ],
]

For pagination

$posts = Post::paginate(20);

$user->attachFavoriteStatus($posts);

N+1 issue

To avoid the N+1 issue, you can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the with method:

// Favoriter
$users = User::with('favorites')->get();

foreach($users as $user) {
    $user->hasFavorited($post);
}

// with favoriteable object
$users = User::with('favorites.favoriteable')->get();

foreach($users as $user) {
    $user->hasFavorited($post);
}

// Favoriteable
$posts = Post::with('favorites')->get();
// or
$posts = Post::with('favoriters')->get();

foreach($posts as $post) {
    $post->isFavoritedBy($user);
}

Events

Event Description
Overtrue\LaravelFavorite\Events\Favorited Triggered when the relationship is created.
Overtrue\LaravelFavorite\Events\Unfavorited Triggered when the relationship is deleted.

Related packages

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

❤️ Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 ❤️

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT

laravel-favorite's People

Contributors

akyuzg avatar alexjustesen avatar hy7716 avatar laravel-shift avatar mahdi-morovati avatar orlyapps avatar overtrue avatar puzzle9 avatar salarmotevalli avatar stichoza avatar sulaiman1000 avatar titonova avatar uptutu avatar yazeedalsaif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-favorite's Issues

Its giving exception

Symfony\Component\Debug\Exception\FatalThrowableError
syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ',' or ')'

public function getFavoriteItems(string $model)

{

    return app($model)->whereHas(

        'favoriters',

        **fn ($q) => $q->where(config('favorite.user_foreign_key'), $this->getKey())**

    );

}

Call to a member function toggleFavorite() on null

i have favoriter user and favoriteable vacancy. When I try to save, I get this error (Call to a member function toggleFavorite() on null).
$vacancy = Vacancy::where('slug',$slug)->firstOrFail();
$response = auth()->user()->toggleFavorite($vacancy);

Installation failed

Hi, i got some error when installing laravel-favorite, composer output is below.

And i also installed laravel-follow and laravel-like, successfully.

I found in composer.json it requires "orchestra/testbench": "~3.7" but laravel-follow and laravel-like don't require it, i guess "orchestra/testbench": "~3.7" in "require" is not necessary? Thank you. 😀

composer require overtrue/laravel-favorite -vvv

Composer output:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - orchestra/testbench v3.7.7 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.6 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.5 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.4 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.3 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.2 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.1 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench v3.7.0 requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - orchestra/testbench 3.7.x-dev requires phpunit/phpunit ^7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2, 7.0.3, 7.1.0, 7.1.1, 7.1.2, 7.1.3, 7.1.4, 7.1.5, 7.2.0, 7.2.1, 7.2.2, 7.2.3, 7.2.4, 7.2.5, 7.2.6, 7.2.7, 7.3.0, 7.3.1, 7.3.2, 7.3.3, 7.3.4, 7.3.5, 7.4.0, 7.4.1, 7.4.2, 7.4.3, 7.4.4, 7.4.5, 7.5.0, 7.5.1, 7.5.10, 7.5.11, 7.5.12, 7.5.13, 7.5.14, 7.5.15, 7.5.16, 7.5.17, 7.5.18, 7.5.19, 7.5.2, 7.5.20, 7.5.3, 7.5.4, 7.5.5, 7.5.6, 7.5.7, 7.5.8, 7.5.9] but these conflict with your requirements or minimum-stability.
    - Conclusion: remove laravel/framework v7.6.1
    - Conclusion: don't install laravel/framework v7.6.1
    - overtrue/laravel-favorite 2.0.1 requires orchestra/testbench ~3.7 -> satisfiable by orchestra/testbench[3.7.x-dev, 3.8.x-dev, 3.9.x-dev, v3.7.0, v3.7.1, v3.7.2, v3.7.3, v3.7.4, v3.7.5, v3.7.6, v3.7.7, v3.8.0, v3.8.1, v3.8.2, v3.8.3, v3.8.4, v3.8.5, v3.9.0, v3.9.1, v3.9.2, v3.9.3].
    - overtrue/laravel-favorite 2.0.0 requires orchestra/testbench ~3.7 -> satisfiable by orchestra/testbench[3.7.x-dev, 3.8.x-dev, 3.9.x-dev, v3.7.0, v3.7.1, v3.7.2, v3.7.3, v3.7.4, v3.7.5, v3.7.6, v3.7.7, v3.8.0, v3.8.1, v3.8.2, v3.8.3, v3.8.4, v3.8.5, v3.9.0, v3.9.1, v3.9.2, v3.9.3].
    - orchestra/testbench 3.8.x-dev requires laravel/framework ~5.8.35 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench v3.8.0 requires laravel/framework ~5.8.0 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench v3.8.1 requires laravel/framework ~5.8.2 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench v3.8.2 requires laravel/framework ~5.8.3 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench v3.8.3 requires laravel/framework ~5.8.19 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench v3.8.4 requires laravel/framework ~5.8.19 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench v3.8.5 requires laravel/framework ~5.8.35 -> satisfiable by laravel/framework[5.8.x-dev].
    - orchestra/testbench 3.9.x-dev requires laravel/framework ^6.18.0 -> satisfiable by laravel/framework[6.x-dev].
    - orchestra/testbench v3.9.0 requires laravel/framework ^6.0 -> satisfiable by laravel/framework[6.x-dev].
    - orchestra/testbench v3.9.1 requires laravel/framework ^6.0 -> satisfiable by laravel/framework[6.x-dev].
    - orchestra/testbench v3.9.2 requires laravel/framework ^6.2 -> satisfiable by laravel/framework[6.x-dev].
    - orchestra/testbench v3.9.3 requires laravel/framework ^6.18.0 -> satisfiable by laravel/framework[6.x-dev].
    - Can only install one of: laravel/framework[5.8.x-dev, v7.6.1].
    - Can only install one of: laravel/framework[6.x-dev, v7.6.1].
    - Installation request for laravel/framework (locked at v7.6.1, required as ^7.0) -> satisfiable by laravel/framework[v7.6.1].
    - Installation request for overtrue/laravel-favorite ^2.0 -> satisfiable by overtrue/laravel-favorite[2.0.0, 2.0.1].

Installation failed, reverting ./composer.json to its original content.

如何优雅地给收藏内容排序?

想达到把最近收藏的内容放在前面。

错误的示例:
$list = $user->getFavoriteItems(Post::class)
->orderBy( "favorites.updated_at", 'desc' )
->simplePaginate( $request->get('limit',10) ); //

Unable to locate publishable resources.

Receive the following error when trying to publish migration files or config files on Laravel 8.

php artisan vendor:publish --provider="Overtrue\\LaravelFavorite\\FavoriteServiceProvider" --tag=migrations
Unable to locate publishable resources.
Publishing complete.

Was able to manually copy package vendor config/favorite.php to app/config/favorite.php

Numeric value out of range

Is it possible to use a unique id string as favoriteable_id in the favorites table? I have a model that uses this and it would be nice if I could get it to work.

[2022-01-12 05:33:26] production.ERROR: SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'favoriteable_id' at row 1 (SQL: insert into `favorites` (`user_id`, `favoriteable_id`, `favoriteable_type`, `updated_at`, `created_at`) values (1, 5e5572ef243e2, App\Models\Parkinglocation, 2022-01-12 05:33:25, 2022-01-12 05:33:25)) {"userId":1,"exception":"[object] (Illuminate\\Database\\QueryException(code: 22003): SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'favoriteable_id' at row 1 (SQL: insert into `favorites` (`user_id`, `favoriteable_id`, `favoriteable_type`, `updated_at`, `created_at`) values (1, 5e5572ef243e2, App\\Models\\Parkinglocation, 2022-01-12 05:33:25, 2022-01-12 05:33:25)) at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:705)

[Request] Morphable favouriter?

Currently we only allow a 'user' to favourite a model, would it be possible in the future to allow many models to favourite many models?

For example:

  • User::class can favourite Status::class
  • Page::class can favourite Image::class
  • Page::class can favourite Status::class

Return value must be of type Illuminate\Database\Query\Builder

image

Since the update to Laravel 9, I get this error. Is this something that can be solved, or is it better to work around it by calling another function?

/**
 * Get a list of user favorites
 */
public static function getFavorites()
{
    if (Auth::check()) {
        $spotter = Auth::user()->getFavoriteItems(Parkinglocation::class)->get();
        $garage = Auth::user()->getFavoriteItems(Parkinggarage::class)->get();
        $city = Auth::user()->getFavoriteItems(Parkingcity::class)->get();
        $favorites = $spotter->merge($garage)->merge($city);
    } else {
        $favorites = [];
    }
    return $favorites;
}

Favourite VS Like

Could you please describe the differences between this package and like package? Do not really get it

syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'

Just updated my composer but when I initialize php artisan serve
i get this error

syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ')'

Then traced the file which the error was coming from

C:\Users\DemiGod\Killer\vendor\overtrue\laravel-favorite\src\Traits\Favoriter.php:81

when i checked the file i saw this

`/**
* Get Query Builder for favorites
*
* @return Illuminate\Database\Eloquent\Builder
*/

public function getFavoriteItems(string $model)
{
    return app($model)->whereHas(
        'favoriters',
        fn ($q) => $q->where(config('favorite.user_foreign_key'), $this->getKey())
    );
}`

The error was coming from here

'favoriters', fn ($q) => $q->where(config('favorite.user_foreign_key'), $this->getKey())

then i added square brackets

['favoriters', fn ($q) => $q->where(config('favorite.user_foreign_key'), $this->getKey())]

Now its working well.

But I do hope that you guys should check that error before it hits everyone that has updated their composer.

Can't publish migrations unless I use `--tag=favorite-migrations`

  • Version: 4.0.1

I tried to publish the migrations according to README:

php artisan vendor:publish --provider="Overtrue\\LaravelFavorite\\FavoriteServiceProvider" --tag=migrations

But it didn't work, I got this message:

No publishable resources for tag [migrations]

And of course, the migration files weren't published.


To fix it, I replaced "migrations" with "favorite-migrations":

php artisan vendor:publish --provider="Overtrue\\LaravelFavorite\\FavoriteServiceProvider" --tag=favorite-migrations

And that worked.

The same issue happens when publishing the configuration file: --tag=config vs --tag=favorite-config.

Also, this issue is preventing the library from working out of the box. After installing it and refreshing the migrations, I got an 1146 Table 'favorites' doesn't exist SQL error.

But forcing the migration files with "favorite-migrations" fixed the issue (it generated the favorites table).

Add support for laravel `^6.0|^7.0|^8.0|^9.0` versions

Thanks for a great work,
I think this package can be compatible with older versions of Laravel as well. You can update composer.json to be compatible with ^6.0|^7.0|^8.0|^9.0 versions.
You should not rely entirely on Laravel Shift #23

Issue with favoriter_model

i have two models related to users one for admin users User and other for customers Customer, I need to apply this package with Customer model, and i seed on your package use the auth.providers.users.model, but as you see i have to provider

'providers' => [ 'users' => [ 'driver' => 'eloquent', 'model' => App\Models\User::class, ], 'customers' => [ 'driver' => 'eloquent', 'model' => App\Models\Customer::class, ] ],

so I suggest to add on `config/favorite.php` 
`'favoriter_model' => App\Models\Customer::class,`
and use this instead of `auth.providers.users.model`

Problems installing

Hi, i was trying to install your package, in Laravel 5.8 but when i try

composer require overtrue/laravel-favorite -vvv

the following error appears:

[InvalidArgumentException]
Could not find package overtrue/laravel-favorite at any version for your minimum-stability (dev). Check the package spelling or your minimum-stability

Any work around?
Regards

Latest version not on Packagist?

Is it true that people cannot use the latest version (5.1.0) because it is not yet on Packagist?
Because of the upgrade to Laravel 10, I'm stuck updating the package in my project

Only allow Logged-In users to Favorite. Collections of favorites.

Hi there,
I want to know that, how can I allow only users that are logged in to favorite and if the user is not logged in it will prompt an error??. So please help me.

And also please tell me if this package has support for collection of favorites. If not and you think of adding it, can you please let me know the estimated time for that upgrade. Hope to see it soon.

By the way, It's a great package overall.

Access Favorite created_at

Thank you for this great package! I was wondering the simplest way of getting the created_at date on the following query

$favorites = $user->getFavoriteItems(Media::class)->latest()->paginate();

In this example, I get the Media model, but none of the information on the favorite item.

I appreciate any input!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.