當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::limit方法代碼示例

本文整理匯總了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);
 }
開發者ID:netxinyi,項目名稱:meigui,代碼行數:33,代碼來源:HomeController.php

示例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);
 }
開發者ID:turuwo3,項目名稱:activerecord,代碼行數:37,代碼來源:RecordAssociationTest.php


注:本文中的App\Model\User::limit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。