本文整理汇总了PHP中App\Model\User::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP User::limit方法的具体用法?PHP User::limit怎么用?PHP User::limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App\Model\User
的用法示例。
在下文中一共展示了User::limit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
//总访问量
$visits = \Cache::get('visits', 0);
//今日注册用户
$todayUsers = User::today()->count('user_id');
//总用户数
$totalUsers = User::count('user_id');
//管理员聊天记录
$chatMessages = AdminMessage::with('admin')->limit(10)->oldest()->get();
//最新留言
$guestBook = GuestBook::with('user')->limit(10)->oldest()->get();
//最新注册用户
$users = User::limit(24)->oldest()->get();
//最新评论
$comments = Comment::limit(10)->oldest()->get();
// 总会员数量/待审核会员/普通会员/高端会员
$user_all_num = User::count('user_id');
$user_shenhe_num = User::status(\App\Enum\User::STATUS_CHECK)->count('user_id');
$user_level1_num = User::level(\App\Enum\User::LEVEL_1)->count('user_id');
$user_level3_num = User::level(\App\Enum\User::LEVEL_3)->count('user_id');
// 自我介绍待审核数量
$user_info_num = UserInfo::where('introduce_status', \App\Enum\User::INTRODUCE_CHECK)->count('user_id');
// 会员相片审核数量
$user_gallery_num = DB::table('user_gallery')->where('status', '待审核')->where('image_url', '!=', '')->count('photo_id');
// 文章数量
$article_num = DB::table('articles')->count('article_id');
$res = array('user_all_num' => $user_all_num, 'user_shenhe_num' => $user_shenhe_num, 'user_level1_num' => $user_level1_num, 'user_level3_num' => $user_level3_num, 'user_info_num' => $user_info_num, 'user_gallery_num' => $user_gallery_num, 'article_num' => $article_num);
return $this->view('index', $res);
// return $this->view('index')->with('visits', $visits)->with('todayUsers', $todayUsers)->with('totalUsers',
// $totalUsers)->with('chatMessages', $chatMessages)->with('guestBook', $guestBook)->with('users',
// $users)->with('comments', $comments);
}
示例2: testLimit
public function testLimit()
{
/*
$conn->query("DELETE FROM users");
$conn->query("INSERT INTO users(id,name) VALUES(1,'bar'), (2, 'foo'), (3, 'hoge'), (4, 'fuga')");
$conn->query("DELETE FROM comments");
$conn->query("INSERT INTO comments(id, text, user_id)
VALUES(1, 'bar comment first', 1), (2, 'bar comment second', 1), (3, 'foo comment first', 2)");
$conn->query("DELETE FROM users_skills");
$conn->query("INSERT INTO users_skills(id, users_id, skills_id)
VALUES(1, 1, 1), (2, 1, 2), (3, 2, 1)");
$conn->query("DELETE FROM skills");
$conn->query("INSERT INTO skills(id, name)
VALUES(1,'skill1'), (2, 'skill2'), (3, 'skill3')");
$conn->query("DELETE FROM profiles");
$conn->query("INSERT INTO profiles(id, text, user_id)
VALUES(1, 'bar profile', 1), (2, 'foo frofile', 2), (3, 'hoge frofile', 3)");
*/
$users = User::limit(4);
$this->assertEquals('bar profile', $users[0]->Profile->text);
$this->assertEquals('foo frofile', $users[1]->Profile->text);
$this->assertEquals('hoge frofile', $users[2]->Profile->text);
$this->assertEquals(null, $users[3]->Profile);
$this->assertEquals('bar comment first', $users[0]->Comment[0]->text);
$this->assertEquals('bar comment second', $users[0]->Comment[1]->text);
$this->assertEquals('foo comment first', $users[1]->Comment[0]->text);
$this->assertEquals([], $users[2]->Comment);
$this->assertEquals([], $users[3]->Comment);
$this->assertEquals('skill1', $users[0]->Skill[0]->name);
$this->assertEquals('skill1', $users[1]->Skill[0]->name);
$this->assertEquals([], $users[2]->Skill);
$this->assertEquals([], $users[3]->Skill);
}