batuhan / laravel-flaggable
为 Laravel Eloquent 模型提供的特性,允许轻松实现“标记”功能。
1.0.0
2015-04-23 22:04 UTC
Requires
- php: >=5.3.0
- illuminate/contracts: 5.*
- illuminate/database: 5.*
Requires (Dev)
- doctrine/dbal: 2.5.*
- orchestra/testbench: 3.0.*
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-09-28 17:32:24 UTC
README
为 Laravel Eloquent 模型提供的特性,允许轻松实现“标记”功能。仅测试于 Laravel 5。
Composer 安装(适用于 Laravel 5)
composer require batuhan/laravel-flagable "~1.0.0"
安装后运行迁移
'providers' => array( 'Conner\Likeable\LikeableServiceProvider', );
php artisan vendor:publish --provider="Conner\Likeable\LikeableServiceProvider"
php artisan migrate
设置你的模型
class Article extends \Illuminate\Database\Eloquent\Model {
use Conner\Likeable\LikeableTrait;
}
示例用法
$article->flag(); // like the article for current user
$article->flag($myUserId); // pass in your own user id
$article->flag(0); // just add flags to the count, and don't track by user
$article->unflag(); // remove flag from the article
$article->unflag($myUserId); // pass in your own user id
$article->unflag(0); // remove flags from the count -- does not check for user
$article->flagCount; // get count of flags
$article->flags; // Iterable Illuminate\Database\Eloquent\Collection of existing flags
$article->flaged(); // check if currently logged in user flaged the article
$article->flaged($myUserId);
Article::whereflaged($myUserId) // find only articles where user flaged them
->with('flagCounter') // highly suggested to allow eager load
->get();
致谢
- Robert Conner - http://smartersoftware.net