当前位置: 首页>>代码示例>>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;未经允许,请勿转载。