本文整理汇总了PHP中app\User::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP User::firstOrNew方法的具体用法?PHP User::firstOrNew怎么用?PHP User::firstOrNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\User
的用法示例。
在下文中一共展示了User::firstOrNew方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: diakkeszites
private function diakkeszites($file)
{
$egyvaltozo1 = Excel::load($file, function ($reader) {
$reader->ignoreEmpty();
})->get(array('hallgatoneptunkodja'))->toArray();
try {
$szamol = User::all()->count();
foreach ($egyvaltozo1 as $egyvaltozo) {
if ($egyvaltozo["hallgatoneptunkodja"] != "") {
$diak = User::firstOrNew(array("name" => $egyvaltozo["hallgatoneptunkodja"], "email" => $egyvaltozo["hallgatoneptunkodja"], "type" => "3"));
if (empty($diak->password)) {
$diak->password = bcrypt($egyvaltozo["hallgatoneptunkodja"]);
$diak->save();
} else {
$diak->active = 1;
$diak->save();
}
}
}
$szamol = User::all()->count() - $szamol;
return $szamol;
} catch (\Exception $e) {
$message = "Import file is not valid! Please check";
return view('import.error', compact('message'));
}
}
示例2: handle
public function handle()
{
$adminUser = User::firstOrNew(['email' => env('ADMIN_EMAIL'), 'name' => 'Cocoaheads Admin']);
$adminUser->password = Hash::make(env('ADMIN_PASSWORD'));
$adminUser->save();
$this->info("Admin User id {$adminUser->id}");
}
示例3: store
public function store(BookingRequest $request)
{
$booking = array('car_type_id' => $request->car_type_id, 'number_of_passengers' => $request->number_of_passengers, 'pickup_time' => $request->pickup_date_part . ' ' . $request->pickup_time_part, 'ip_info' => $request->ip_info);
$newBooking = Booking::create($booking);
flash()->success('Your booking has been created!')->important();
if (!empty($request->comment1)) {
//children comment
$comment1 = array('booking_id' => $newBooking->id, 'comment_type_id' => '1', 'role_id' => '1', 'comment' => $request->comment1);
Comment::create($comment1);
}
if (!empty($request->comment2)) {
//general comment
$comment2 = array('booking_id' => $newBooking->id, 'comment_type_id' => '2', 'role_id' => '1', 'comment' => $request->comment2);
Comment::create($comment2);
}
$change = array('booking_id' => $newBooking->id, 'change_type_id' => '4', 'user_id' => Auth::user()->id, 'from' => null, 'to' => null);
Change::create($change);
$passenger = User::firstOrNew(['email' => $request->email]);
$passenger->name = $request->name;
$passenger->phone = $request->phone;
$passenger->save();
$role = array('booking_id' => $newBooking->id, 'role_type_id' => '2', 'user_id' => $passenger->id);
Role::create($role);
$price = array('booking_id' => $newBooking->id, 'income_type_id' => '1', 'amount_eur' => $request->price);
Income::create($price);
$locationArray = $request->location;
foreach ($request->address as $order => $address_id) {
$route_point = null;
$route_point = array('booking_id' => $newBooking->id, 'location_id' => $locationArray[$order], 'address_id' => $address_id, 'order' => $order);
Route_point::create($route_point);
}
return redirect('bookings');
}
示例4: register
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton('App\\User', function ($app) {
// Session中获取当前认证用户
$authUser = session('logged_user');
if (true || app()->environment('debug')) {
$authUser = (object) array('id' => 'Hello, World!');
}
if (empty($authUser)) {
$oauth = app('wechat')->oauth;
try {
$authUser = $oauth->user();
} catch (\InvalidArgumentException $e) {
$response = $oauth->scopes(['snsapi_base'])->redirect();
return $response;
}
// 保存Session
//$authUser = $oauth->user();
session(['logged_user' => $authUser]);
}
// 根据认证得到的用户openid获取用户信息,若不存在则实例化新用户
$user = User::firstOrNew(['openid' => $authUser->id]);
if ($user->state == 'normal' && $user->score <= 0) {
$user->state = 'disabled';
$user->save();
} else {
if ($user->score > 0 && $user->state == 'disabled' && $user->free_at && $user->free_at->lte(Carbon::now())) {
$user->state = 'normal';
$user->save();
}
}
return $user;
});
}
示例5: findOrCreateUser
public function findOrCreateUser($googleUser)
{
$authUser = User::firstOrNew(['email' => $googleUser->email]);
$authUser->token = Crypt::encrypt(json_encode($googleUser->token));
$authUser->save();
return $authUser;
}
示例6: findByEmailOrCreate
/**
* Given an array of formatted user data,
* return a valid user model
*
* @param array $userData
* @return static
*/
public function findByEmailOrCreate($userData)
{
//find user by email
$user = User::firstOrNew(['email' => $userData['email']]);
//save all new data to the record
$user->save($userData);
return $user;
}
示例7: handleProviderCallback
/**
* Obtain the user information from GitHub.
*
* @return Response
*/
public function handleProviderCallback()
{
$gitUser = Socialite::driver('github')->user();
$user = User::firstOrNew(['username' => $gitUser->nickname, 'name' => $gitUser->name, 'email' => $gitUser->email]);
$user->github_token = $gitUser->token;
$user->save();
auth()->login($user);
return redirect('/gists');
}
示例8: getFacebookCallback
public function getFacebookCallback(Request $req)
{
$user = \Socialite::with('facebook')->user();
$data = array('name' => $user->name, 'email' => $user->email, 'password' => $req['code']);
$request = new Request();
$request = User::firstOrNew($data);
$request->save();
Auth::login($request);
return redirect('');
}
示例9: handleProviderCallback
/**
* Obtain the user information from FaceBook.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('facebook')->user();
// create in database if null
$save = User::firstOrNew(array('name' => $user->getName(), 'username' => $user->getNickname(), 'email' => $user->getEmail(), 'avatar' => $user->getAvatar(), 'provider' => 'facebook', 'provider_id' => $user->getId()));
$save->save();
//put id and name into session
Session::put('provider_id', $user->getId());
Session::put('name', $user->getName());
return redirect('/main');
}
示例10: requireAuthenticationForRoute
public function requireAuthenticationForRoute(FunctionalTester $I)
{
$I->dontSeeAuthentication();
$I->amOnPage('/secure');
$I->seeCurrentUrlEquals('/auth/login');
$I->see('Login');
$I->amLoggedAs(User::firstOrNew($this->userAttributes));
$I->amOnPage('/secure');
$I->seeResponseCodeIs(200);
$I->see('Hello World');
}
示例11: findByEmailOrCreate
public function findByEmailOrCreate($userData)
{
$user = User::firstOrNew(['email' => $userData->email]);
if (!$user->exists) {
$name = $this->splitName($userData->name);
$user->f_name = $name[0];
$user->l_name = $name[1];
$user->save();
}
return $user;
}
示例12: handleProviderCallback
/**
* Obtain the user information from Facebook.
*
* @return Response
*/
public function handleProviderCallback()
{
$user = Socialite::driver('facebook')->user();
$newUser = User::firstOrNew(['email' => $user->email]);
$newUser->name = $user->name;
$newUser->facebook_id = $user->id;
$newUser->first_name = $user->user['first_name'];
$newUser->last_name = $user->user['last_name'];
$newUser->save();
// dd($newUser);
Auth::login($newUser, true);
return redirect(route('alerts.index'));
}
示例13: updateUsers
private function updateUsers($data)
{
foreach ($data as $row) {
$user = User::firstOrNew(['id' => $row->id]);
$user->name = $row->name;
$user->email = $row->email;
$user->thumb_url = $row->thumb_url;
$user->about = $row->about;
$user->phone = $row->phone;
$user->facebook = $row->facebook;
$user->save();
}
return '/admin/user';
}
示例14: socialCallback
public function socialCallback($provider)
{
$socialProviderType = SocialProviderType::where('name', $provider)->first();
$socialProviderData = Socialize::with($provider)->user()->map([]);
$socialProvider = SocialProvider::where('social_provider_id', $socialProviderData->id)->where('social_provider_type_id', $socialProviderType->id)->first();
if (Auth::check()) {
$user = Auth::user();
if (!$socialProvider) {
$socialProvider = new SocialProvider();
$socialProvider->token = isset($socialProviderData->token) ? $socialProviderData->token : null;
$socialProvider->social_provider_id = isset($socialProviderData->id) ? $socialProviderData->id : null;
$socialProvider->token_secret = isset($socialProviderData->tokenSecret) ? $socialProviderData->tokenSecret : '';
$socialProvider->social_provider_type_id = $socialProviderType->id;
$socialProvider->nickname = '' + $socialProviderData->nickname;
$socialProvider->email = $socialProviderData->email;
$socialProvider->name = $socialProviderData->name;
$socialProvider->avatar = $socialProviderData->avatar;
$socialProvider->other_provider_info = \Psy\Util\Json::encode($socialProviderData);
$socialProvider->save();
$user->socialProviders()->save($socialProvider);
Auth::login($user);
}
} else {
if ($socialProvider) {
Auth::login($socialProvider->user);
} else {
$socialProvider = new SocialProvider();
$socialProvider->token = isset($socialProviderData->token) ? $socialProviderData->token : null;
$socialProvider->social_provider_id = isset($socialProviderData->id) ? $socialProviderData->id : null;
$socialProvider->token_secret = isset($socialProviderData->tokenSecret) ? $socialProviderData->tokenSecret : '';
$socialProvider->social_provider_type_id = $socialProviderType->id;
$socialProvider->nickname = '' + $socialProviderData->nickname;
$socialProvider->email = $socialProviderData->email;
$socialProvider->name = $socialProviderData->name;
$socialProvider->avatar = $socialProviderData->avatar;
$socialProvider->other_provider_info = \Psy\Util\Json::encode($socialProviderData);
$socialProvider->save();
$user = User::firstOrNew(['email' => $socialProvider->email]);
$user->name = isset($user->name) ? $user->name : $socialProvider->name;
$user->username = null;
$user->password = null;
$user->email = isset($user->email) ? $user->email : $socialProvider->email;
$user->avatar = isset($user->avatar) ? $user->avatar : $socialProvider->avatar;
$user->save();
$user->socialProviders()->save($socialProvider);
Auth::login($user);
}
}
}
示例15: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$credentials = ['email' => $this->argument('email')];
$user = User::firstOrNew($credentials);
if (!$user->isDirty()) {
$this->info('User already exists');
return;
}
$user->name = $this->argument('name');
$user->rights = $this->option('admin') ? ['admin'] : [];
$user->save();
\Password::sendResetLink($credentials, function (Message $message) {
$message->subject('Velkommen til ub-baser');
});
$this->info('User created, email sent to ' . $user->email . '.');
}