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


PHP User::first方法代碼示例

本文整理匯總了PHP中app\User::first方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::first方法的具體用法?PHP User::first怎麽用?PHP User::first使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\User的用法示例。


在下文中一共展示了User::first方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testDestroyReturnsJsonResponseInstance

 public function testDestroyReturnsJsonResponseInstance()
 {
     $users = Factory::times(5)->create('App\\User');
     $currentUser = User::first();
     Auth::login($currentUser);
     $controller = new FriendController($currentUser);
     $request = new Request(['userId' => 2]);
     $response = $controller->destroy($request);
     $this->assertInstanceOf('Illuminate\\Http\\JsonResponse', $response);
 }
開發者ID:talha08,項目名稱:Larasocial,代碼行數:10,代碼來源:TestFriendController.php

示例2: testVerify

 function testVerify()
 {
     // Given
     $this->startSession();
     $userData = ['name' => 'Some name', 'email' => 'sname@enterprise.awesome', 'password' => 'strongpassword', 'country_code' => '1', 'phone_number' => '5558180101'];
     $user = new User($userData);
     $user->authy_id = 'authy_id';
     $user->save();
     $this->be($user);
     $mockAuthyApi = Mockery::mock('Authy\\AuthyApi')->makePartial();
     $mockVerification = Mockery::mock();
     $mockTwilioClient = Mockery::mock(\Twilio\Rest\Client::class)->makePartial();
     $mockTwilioClient->messages = Mockery::mock();
     $twilioNumber = config('services.twilio')['number'];
     $mockTwilioClient->messages->shouldReceive('create')->with($user->fullNumber(), ['body' => 'You did it! Signup complete :)', 'from' => $twilioNumber])->once();
     $mockAuthyApi->shouldReceive('verifyToken')->with($user->authy_id, 'authy_token')->once()->andReturn($mockVerification);
     $mockVerification->shouldReceive('ok')->once()->andReturn(true);
     $this->app->instance(\Twilio\Rest\Client::class, $mockTwilioClient);
     $this->app->instance('Authy\\AuthyApi', $mockAuthyApi);
     $modifiedUser = User::first();
     $this->assertFalse($modifiedUser->verified);
     // When
     $response = $this->call('POST', route('user-verify'), ['token' => 'authy_token', '_token' => csrf_token()]);
     // Then
     $modifiedUser = User::first();
     $this->assertRedirectedToRoute('user-index');
     $this->assertTrue($modifiedUser->verified);
 }
開發者ID:TwilioDevEd,項目名稱:account-verification-laravel,代碼行數:28,代碼來源:UserControllerTest.php

示例3: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::first();
     if (!$user) {
         $this->error('No user to import articles to');
         return;
     }
     $archives = PostCategory::where('name', 'archives')->first();
     if (!$archives) {
         $archives = PostCategory::create(['name' => 'archives', 'description' => 'old posts from prev site']);
     }
     $this->archiveId = $archives->id;
     $upperBound = intval($this->ask('What is the upper bound for the article ids?'));
     $articlesToFetch = collect(ImportResult::getMissingIdsUpToLimit($upperBound));
     $articlesToFetch->each(function ($id) use($user) {
         try {
             $reader = $this->articleReader->getPage($id);
             $this->import($reader, $id, $user);
             ImportResult::create(['article_id' => $id, 'imported' => 1]);
         } catch (\Exception $e) {
             $this->error('Failed on article ' . $id . ' : ' . $e->getMessage());
             ImportResult::create(['article_id' => $id, 'imported' => 0]);
         }
     });
 }
開發者ID:michaeljoyner,項目名稱:complete,代碼行數:30,代碼來源:ImportArticles.php

示例4: __construct

 /**
  * Constructor.
  */
 public function __construct()
 {
     if (Auth::guest()) {
         \Auth::login(User::first());
     }
     $this->currentUser = \Auth::user();
 }
開發者ID:progjp,項目名稱:rest_api,代碼行數:10,代碼來源:Controller.php

示例5: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     //Get the Number of Orders
     $count = Order::todaysOrders();
     JavaScript::put(['foo' => 'bar', 'user' => User::first(), 'age' => 29]);
     return view('pages.index', ['count' => $count]);
 }
開發者ID:jamesddube,項目名稱:mps-server,代碼行數:12,代碼來源:DashboardController.php

示例6: testFetchesInheritedClasses

 public function testFetchesInheritedClasses()
 {
     factory(User::class)->create(['type' => Employee::class]);
     $employee = User::first();
     $this->assertEquals(Employee::class, $employee->type);
     $this->assertInstanceOf(Employee::class, $employee);
 }
開發者ID:tonysm,項目名稱:laravel-sti,代碼行數:7,代碼來源:ExampleTest.php

示例7: testGet

 public function testGet()
 {
     $users = User::get();
     $this->assertEquals(3, $users->count());
     $users = User::where('id', '>', 1)->get();
     $this->assertEquals(2, $users->count());
     // test chunk
     User::chunk(2, function ($users) {
         foreach ($users as $user) {
             $this->assertInternalType('int', $user->id);
         }
     });
     User::chunk(1, function ($users) {
         $this->assertInstanceOf('Illuminate\\Support\\Collection', $users);
     });
     // test find with query builder
     $user = User::where('id', '>', 1)->find(1);
     $this->assertNull($user);
     $user = User::where('id', '>', 1)->find(2);
     $this->assertEquals(2, $user->id);
     // test first without query builder
     $user = User::first();
     $this->assertInstanceOf('App\\User', $user);
     // test retrieving aggregates
     $max_id = User::max('id');
     $this->assertGreaterThanOrEqual(3, $max_id);
     $count = User::count();
     $this->assertGreaterThanOrEqual(3, $count);
     $sum = User::sum('id');
     $this->assertGreaterThanOrEqual(6, $sum);
 }
開發者ID:richarddlu,項目名稱:test_eloquent,代碼行數:31,代碼來源:EloquentTest.php

示例8: customCreate

 public static function customCreate(CreateConversationRequest $request)
 {
     $conv = new Conversation();
     $conv->Title = $request->Title;
     // if nothing specified in the request
     if (!$request->has('user_id')) {
         // if we are not even logged ( happen while seeding base)
         if (!\Auth::check()) {
             $conv->user_id = User::first()->id;
         } else {
             $conv->user_id = \Auth::id();
         }
     }
     // if Pending status is specified we take it, if not default value will be applied (false)
     if (!$request->has('Pending')) {
         $conv->Pending = $request->Pending;
     }
     $conv->created_at = Carbon::now();
     $conv->save();
     // When conversation is settled the Thread can be created
     $thread = new Thread();
     $thread->user_id = $conv->user_id;
     $thread->Content = $request->Content;
     $thread->conversation_id = $conv->id;
     $thread->created_at = Carbon::now();
     $thread->Pending = $conv->Pending;
     $thread->save();
     return true;
 }
開發者ID:yves01,項目名稱:dashboard,代碼行數:29,代碼來源:Conversation.php

示例9: tagged

 /**
  * Display a listing of the resource associated with the tag name.
  *
  * @param Tag $tag
  * @return \Illuminate\Http\Response
  */
 public function tagged(Tag $tag)
 {
     $admin = User::first();
     $tags = Tag::all();
     $articles = $tag->publishedArticles()->get();
     $currentTag = $tag;
     return view($this->theme() . 'home', compact('articles', 'currentTag', 'admin', 'tags'));
 }
開發者ID:realnerdo,項目名稱:portfolio,代碼行數:14,代碼來源:ThemeController.php

示例10: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $payment = User::first()->payments()->create(['completed' => 1, 'money' => 15000]);
     $payment->arrears()->create(['user_id' => 2, 'money' => 5000, 'confirm' => 3]);
     $payment->arrears()->create(['user_id' => 3, 'money' => 10000, 'confirm' => 3]);
     $payment = User::find(4)->payments()->create(['completed' => 0, 'money' => 10000]);
     $payment->arrears()->create(['user_id' => 1, 'money' => 5000, 'confirm' => 3]);
     $payment->arrears()->create(['user_id' => 3, 'money' => 2000, 'confirm' => 1]);
 }
開發者ID:LFKv3,項目名稱:backend,代碼行數:14,代碼來源:PaymentTableSeeder.php

示例11: run

 /**
  *
  */
 public function run()
 {
     Recipe::truncate();
     DB::table('food_recipe')->truncate();
     DB::table('taggables')->truncate();
     $this->user = User::first();
     $this->faker = Faker::create();
     $this->createRecipes();
 }
開發者ID:JennySwift,項目名稱:health-tracker,代碼行數:12,代碼來源:RecipeSeeder.php

示例12: create

 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $firstadmin = 0;
     $check = \App\User::first();
     if ($check === null) {
         $firstadmin = 1;
     }
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'isAdmin' => $firstadmin]);
 }
開發者ID:slaleye,項目名稱:securechat,代碼行數:15,代碼來源:AuthController.php

示例13: a_user_can_post_to_a_category

 /**
  * @test
  */
 public function a_user_can_post_to_a_category()
 {
     $this->withoutMiddleware();
     $user = User::first();
     $category = factory(PostCategory::class)->create();
     $response = $this->call('POST', '/admin/users/' . $user->id . '/blog/categories/' . $category->id . '/posts', ['title' => 'My First Blog Post']);
     $this->assertEquals(302, $response->status());
     $this->seeInDatabase('posts', ['user_id' => $user->id, 'post_category_id' => $category->id, 'title' => 'My First Blog Post']);
 }
開發者ID:michaeljoyner,項目名稱:complete,代碼行數:12,代碼來源:PostsTest.php

示例14: run

 public function run()
 {
     $faker = Faker::create();
     $types = ['post', 'page', 'post'];
     $user = User::first();
     foreach (range(1, 10) as $index) {
         DB::table('exp_categories')->insert(['title' => $faker->name, 'description' => $faker->paragraph(5), 'created_by' => $user->id, 'type' => $types[array_rand($types)], 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
     }
 }
開發者ID:vnzacky,項目名稱:dog,代碼行數:9,代碼來源:CategoriesTableSeeder.php

示例15: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Rules
     $role = new Role();
     $roleAdmin = $role->create(['name' => 'Administrador', 'slug' => 'administrator', 'description' => 'Administrador geral do sistema']);
     $user = User::first();
     if ($user) {
         $user->assignRole($roleAdmin);
     }
 }
開發者ID:rafaelpv,項目名稱:tpms-dashboard,代碼行數:15,代碼來源:AclTableSeeders.php


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