本文整理汇总了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);
}
示例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);
}
示例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]);
}
});
}
示例4: __construct
/**
* Constructor.
*/
public function __construct()
{
if (Auth::guest()) {
\Auth::login(User::first());
}
$this->currentUser = \Auth::user();
}
示例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]);
}
示例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);
}
示例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);
}
示例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;
}
示例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'));
}
示例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]);
}
示例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();
}
示例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]);
}
示例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']);
}
示例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()]);
}
}
示例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);
}
}