本文整理汇总了PHP中Rating::reguard方法的典型用法代码示例。如果您正苦于以下问题:PHP Rating::reguard方法的具体用法?PHP Rating::reguard怎么用?PHP Rating::reguard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Rating
的用法示例。
在下文中一共展示了Rating::reguard方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUserSumRating
public function testUserSumRating()
{
Rating::unguard();
$post1 = Post::find(1);
$post2 = Post::find(2);
$user1 = User::find(1);
Rating::create(['id' => 5, 'rating' => 1, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
Rating::create(['id' => 6, 'rating' => 1, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
Rating::reguard();
$this->assertEquals(6, Post::find(1)->userSumRating);
$this->assertEquals(6, Post::find(1)->userSumRating());
$this->assertEquals(2, Post::find(2)->userSumRating);
$this->assertEquals(2, Post::find(2)->userSumRating());
}
示例2: run
public function run()
{
DB::table('ratings')->delete();
Rating::unguard();
$post1 = Post::find(1);
$post2 = Post::find(2);
$post3 = Post::find(3);
$user1 = User::find(1);
$user2 = User::find(2);
Rating::create(['id' => 1, 'rating' => 5, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
Rating::create(['id' => 2, 'rating' => 5, 'rateable_id' => $post1->id, 'rateable_type' => 'Post', 'user_id' => $user2->id]);
Rating::create(['id' => 3, 'rating' => 1, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user1->id]);
Rating::create(['id' => 4, 'rating' => 5, 'rateable_id' => $post2->id, 'rateable_type' => 'Post', 'user_id' => $user2->id]);
Rating::reguard();
}