承接 hamedov/laravel-favorites 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hamedov/laravel-favorites

Composer 安装命令:

composer require hamedov/laravel-favorites

包简介

Manage user favorites in laravel application.

README 文档

README

Manage user favorites in laravel application.

Installation

composer require hamedov/laravel-favorites

Publish config file

php artisan vendor:publish --provider="Hamedov\Favorites\FavoritesServiceProvider" --tag="config"

Set user model in config file

  • Make sure you do this before migrations
    return [
        'user_model' => \App\User::class,
    ];
    

Execute migrations

php artisan migrate

Setup user model

  • Add Hamedov\Favorites\HasFavorites trait to your user model
    class User extends Model {
      use HasFavorites;
    }
    

Usage

  • Add item to user favorites

    $book = Book::find(1);
    $user->addFavorite($book);
    
    $ad = Ad::find(1);
    $user->addFavorite($ad);
    
  • Remove item from user favorites

    $book = Book::find(1);
    $user->removeFavorite($book);
    
  • Get user favorites of specific type

    $favorites = $user->favorites('App\Book')->get();
    // Or
    $favorites = $user->favorites('App\Book')->paginate(10);
    
  • Get user favorite ids of specific type

    // This will return a collection of book ids
    // Passing null as a parameter will return all ids
    $favorites = $user->favoriteIds('App\Book');
    
  • Get use favorite ids with corresponding types, i.e, pivot table entries

    $favorables = $user->favorables()->get();
    // Or pass type as parameter to get only specific type
    $favorables = $user->favorables('App\Ad')->get();
    
  • Remove all user favorites

    $user->flushFavorites();
    // Or
    $user->flushFavorites('App\Book');
    

Available scopes

  • hasFavorite Scope users who added specific model to favorites

    $book = Book::find(1);
    $users = App\User::hasFavorite($book)->get();
    
  • hasFavoriteOfType Scope users who add any model of specific type to favorites

    $users = App\User::hasFavoriteOfType('App\Book')->get();
    

License

Released under the Mit license, see LICENSE

统计信息

  • 总下载量: 643
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固