tobischulz/laravel-favoritable
最新稳定版本:1.4.1
Composer 安装命令:
composer require tobischulz/laravel-favoritable
包简介
Adds an easy way to make every model favoritable
README 文档
README
Adds an easy way to make every model favoritable.
Installation
You can install the package via composer:
composer require tobischulz/laravel-favoritable
Publish all required assets:
php artisan vendor:publish --provider=TobiSchulz\Favoritable\FavoritableServiceProvider
Migrate your database:
php artisan migrate
Preparation
Add trait to eloquent model that you like to be favoritable.
<?php namespace App; use Illuminate\Database\Eloquent\Model; use TobiSchulz\Favoritable\Traits\Favoriteable; class Post extends Model { use Favoriteable; // ... }
Add trait your user model that will have favorites.
<?php namespace App; use Illuminate\Foundation\Auth\User as Authenticatable; use TobiSchulz\Favoritable\Traits\HasFavorites; class User extends Authenticatable { use HasFavorites; // ... }
Usage
<?php /** * API for Favoritable */ $post = Post::find(1); $post->addFavorite(); // adds this post to favorites to current user $post->removeFavorite(); // remove this post from favorites $post->toggleFavorite(); // toggle this post as favorite $post->isFavorited(); // returns boolean for this post favorite state $post = Post::find(1); $user = User::find(2); $post->addFavorite($user); // adds favorite for this post and a specific user. /** * API for HasFavorites */ $user = User::find(1); $user->favorites(Post::class); // returns collection of Post::class favorites
Testing
wip
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email tobias@byte.software instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 3.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-14