本文整理匯總了PHP中app\User::firstOrCreate方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::firstOrCreate方法的具體用法?PHP User::firstOrCreate怎麽用?PHP User::firstOrCreate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\User
的用法示例。
在下文中一共展示了User::firstOrCreate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: handleFbCallback
public function handleFbCallback()
{
$fb_user = Socialite::driver('facebook')->user();
$user = User::firstOrCreate(['firstname' => $fb_user->user['first_name'], 'lastname' => $fb_user->user['last_name'], 'email' => $fb_user->email]);
Auth::login($user, true);
return Redirect::to('/books');
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = \App\User::firstOrCreate(['email' => 'orange@edward.com']);
$user->name = 'Orange';
$user->email = 'orange@edward.com';
$user->password = \Hash::make('helloworld');
$user->user_role = 'leader';
$user->user_group = 'Orange Fellowship';
$user->user_verified = true;
$user->save();
$user = \App\User::firstOrCreate(['email' => 'jill@harvard.edu']);
$user->name = 'Jill';
$user->email = 'jill@harvard.edu';
$user->password = \Hash::make('helloworld');
$user->user_role = 'leader';
$user->user_group = 'Joshua 1 Fellowship';
$user->user_verified = false;
$user->save();
$user = \App\User::firstOrCreate(['email' => 'jamal@harvard.edu']);
$user->name = 'Jamal';
$user->email = 'jamal@harvard.edu';
$user->password = \Hash::make('helloworld');
$user->user_role = 'admin';
$user->user_group = 'Global';
$user->user_verified = true;
$user->save();
$user = \App\User::firstOrCreate(['email' => 'jack@harvard.edu']);
$user->name = 'Jack';
$user->email = 'jack@harvard.edu';
$user->password = \Hash::make('helloworld');
$user->user_role = 'viewer';
$user->user_group = 'Joshua 1 Fellowship';
$user->user_verified = true;
$user->save();
}
示例3: Usuarios
public function Usuarios($action = null)
{
if (isset($action)) {
if ($action == "create") {
$data = User::firstOrCreate(Input::except("_token", "_user"));
return $respuesta = array('Record' => $data, 'Result' => "OK");
}
if ($action == "edit") {
User::where("id", Input::get("id"))->update(Input::except("_token", "id", "_user"));
return $respuesta = array('Record' => User::find(Input::get('id')), 'Result' => "OK");
}
if ($action == "remove") {
User::where('id', Input::get("id"))->delete();
return '{"Result":"OK"}';
}
if ($action == "list") {
$Records = User::get();
$respuesta = array('Records' => $Records, 'Result' => "OK");
return json_encode($respuesta);
}
if ($action == "empresas") {
$nulos = DB::table('empresas')->select(DB::raw("'NO POSEE' as DisplayText, NULL as Value"));
$respuesta = DB::table('empresas')->select("nombre as DisplayText", "id as Value")->union($nulos)->orderby('value', 'asc')->distinct()->get();
return "var opciones=" . json_encode($respuesta);
}
}
}
示例4: authenticate
/**
* authenticate
*
* @param Request $request
* @return Response
*/
public function authenticate(Request $request)
{
$code = $request->input('code');
if ($code) {
$token = $this->api->tokenExchange($code);
if (isset($token->athlete)) {
// changing to use email instead of access token since access token apparently changes
$user = User::firstOrCreate(['email' => $token->athlete->email]);
if (!$user->strava_token) {
Mail::send('emails.newuser', ['name' => $token->athlete->firstname . " " . $token->athlete->lastname], function ($message) {
$message->from('admin@stravabestefforts.com', 'Strava BE');
$message->to(env('MANDRILL_EMAIL'), 'Austin Ducworth')->subject('New Strava BE User');
});
}
// fill in data
$user->strava_token = $token->access_token;
$user->name = $token->athlete->firstname . " " . $token->athlete->lastname;
$user->profile_medium = $token->athlete->profile_medium;
$user->city = $token->athlete->city;
$user->state = $token->athlete->state;
$user->country = $token->athlete->country;
$user->sex = $token->athlete->sex;
$user->premium = $token->athlete->premium;
$user->date_preference = $token->athlete->date_preference;
$user->measurement_preference = $token->athlete->measurement_preference;
$user->email = $token->athlete->email;
$user->password = bcrypt('stravapassword');
$user->save();
if (Auth::attempt(['email' => $token->athlete->email, 'password' => 'stravapassword'])) {
return redirect()->intended('strava/running');
}
}
}
}
示例5: callback
/**
* Callback action that should be called by auth0, logs the user in
*/
public function callback()
{
// Get a handle of the Auth0 service (we don't know if it has an alias)
$service = \App::make('auth0');
// Try to get the user information
$profile = $service->getUser();
// Get the user related to the profile
$auth0User = $this->userRepository->getUserByUserInfo($profile);
if ($auth0User) {
if (!str_contains($auth0User->name, '@')) {
$name = $auth0User->name;
} else {
$name = $auth0User->nickname;
}
// If we have a user, we are going to log him in, but if
// there is an onLogin defined we need to allow the Laravel developer
// to implement the user as he wants an also let him store it.
$flight = User::firstOrCreate(['github_id' => $auth0User->user_id, 'email' => $auth0User->email, 'picture' => $auth0User->picture, 'name' => $name]);
if ($service->hasOnLogin()) {
$user = $service->callOnLogin($auth0User);
} else {
// If not, the user will be fine
$user = $auth0User;
}
\Auth::login($user);
}
return \Redirect::intended('/');
}
示例6: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//User 1
//Necessary user columns
$user = \App\User::firstOrCreate(['email' => 'jill@harvard.edu']);
$user->name = 'Jill';
$user->email = 'jill@harvard.edu';
$user->password = \Hash::make('helloworld');
//User profile columns
$user->birthday = Carbon\Carbon::now()->subYears(21);
$user->gender = 'Woman';
$user->pronouns = "she/her";
$user->save();
//User 2 - used to demonstrate inability to access posts by a user you are not sign in as
//Necessary user columns
$user = \App\User::firstOrCreate(['email' => 'jamal@harvard.edu']);
$user->name = 'Jamal';
$user->email = 'jamal@harvard.edu';
$user->password = \Hash::make('helloworld');
//User profile columns
$user->birthday = Carbon\Carbon::now()->subDays(20)->subYears(28);
$user->gender = 'Man';
$user->pronouns = "he/him";
$user->save();
//User 3 - used to demonstrate how a lack of posts or profile information is handled
//Necessary user columns
$user = \App\User::firstOrCreate(['email' => 'jan@harvard.edu']);
$user->name = 'Jan';
$user->email = 'jan@harvard.edu';
$user->password = \Hash::make('helloworld');
$user->save();
}
示例7: handleProviderCallback
/**
* Obtain the user information from Google..
*
* @return Response
*/
public function handleProviderCallback(Request $request)
{
$googleUser = Socialite::driver('google')->user();
$user = User::firstOrCreate(['email' => $googleUser->getEmail(), 'name' => $googleUser->getName()]);
Auth::login($user);
$request->session()->put('user', Auth::user());
return redirect('/consejo');
}
示例8: login
public function login(Request $request)
{
$token = $request['id_token'];
$user_data = $this->create_gclient($token);
$user = User::firstOrCreate(['name' => $user_data['name'], 'email' => $user_data['email']]);
Auth::login($user);
return redirect(route('user.show'));
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = \App\User::firstOrCreate(['email' => 'john@harvard.edu']);
$user->name = 'John';
$user->email = 'john@harvard.edu';
$user->password = \Hash::make('helloworld');
$user->save();
}
示例10: getLogin
/**
* Store a newly created resource in storage.
* @Get("/{provider}/callback", as="social.login.getLogin")
* @param string $provider
* @return \Illuminate\Http\Response
*/
public function getLogin($provider)
{
$userData = Socialite::with($provider)->user();
Log::debug(print_r($userData, true));
$user = User::firstOrCreate(['username' => $userData->nickname, 'email' => $userData->email]);
Auth::login($user);
return response()->redirectToRoute('articles.getIndex');
}
示例11: findByUsernameOrCreate
public function findByUsernameOrCreate($userData)
{
$user = User::where('email', '=', $userData->email)->first();
if (!$user) {
return User::firstOrCreate(['name' => $userData->name, 'email' => $userData->email]);
}
return $user;
}
示例12: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$posts = factory(Post::class, 10)->create();
$user = \App\User::firstOrCreate(['name' => 'helfull', 'email' => 'admin@helfull.de']);
$posts->each(function ($post) use($user) {
$post->user()->associate($user);
$post->save();
});
}
示例13: store
public function store(Request $request)
{
$user = User::firstOrCreate(['name' => $request->name, 'email' => $request->email, 'password' => bcrypt($request->password)]);
if ($request->input('role_list')) {
$user->roles()->sync($request->input('role_list'));
}
Flash::success('User Created!');
return redirect()->action('UserController@index');
}
示例14: findByUsernameOrCreate
public function findByUsernameOrCreate($userData, $socialiteName)
{
if ($socialiteName == 'weibo') {
return User::firstOrCreate(['name' => $userData->nickname, 'avatar' => $userData->avatar, 'weibo_id' => $userData->id]);
} elseif ($socialiteName == 'weixin') {
return User::firstOrCreate(['name' => $userData->nickname, 'avatar' => $userData->headimgurl, 'weixin_id' => $userData->openid]);
} elseif ($socialiteName = 'github') {
return User::firstOrCreate(['name' => $userData->id, 'nickname' => $userData->nickname, 'avatar' => $userData->avatar]);
}
}
示例15: findByUsernameOrCreate
public function findByUsernameOrCreate($provider, $userData)
{
$user = User::firstOrCreate(['provider_id' => $userData->id, 'provider' => $provider]);
$user->email = $userData->email;
$user->name = $userData->name;
$user->nickname = $userData->nickname;
$user->avatar = $userData->avatar;
$user->save();
return $user;
}