PHP User::firstOrCreate Examples

PHP User::firstOrCreate - 14 examples found. These are the top rated real world PHP examples of User::firstOrCreate extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = [['name' => 'Fake1', 'email' => 'fake1@nosprawl.com', 'username' => 'fake1', 'password' => Hash::make('password123'), 'full_name' => 'Fake1 McFakester'], ['name' => 'Fake2', 'email' => 'fake2@nosprawl.com', 'username' => 'fake2', 'password' => Hash::make('password123'), 'full_name' => 'Fake2 Fakestein'], ['name' => 'Fake3', 'email' => 'fake3@nosprawl.com', 'username' => 'fake3', 'password' => Hash::make('password123'), 'full_name' => 'Fake3 Fakeconi'], ['name' => 'Fake4', 'email' => 'fake4@nosprawl.com', 'username' => 'fake4', 'password' => Hash::make('password123'), 'full_name' => 'Fake4 Fakes'], ['name' => 'Fake5', 'email' => 'fake5@nosprawl.com', 'username' => 'fake5', 'password' => Hash::make('password123'), 'full_name' => 'Fake5 Fakester'], ['name' => 'Fake6', 'email' => 'fake6@nosprawl.com', 'username' => 'fake6', 'password' => Hash::make('password123'), 'full_name' => 'Fake6 Fakess'], ['name' => 'Fake7', 'email' => 'fake7@nosprawl.com', 'username' => 'fake7', 'password' => Hash::make('password123'), 'full_name' => 'Fake7 Fakesterich'], ['name' => 'Fake8', 'email' => 'fake8@nosprawl.com', 'username' => 'fake8', 'password' => Hash::make('password123'), 'full_name' => 'Fake8 Fakesterykos'], ['name' => 'Fake9', 'email' => 'fake9@nosprawl.com', 'username' => 'fake9', 'password' => Hash::make('password123'), 'full_name' => 'Fake9 Fakesterian'], ['name' => 'Fake0', 'email' => 'fake0@nosprawl.com', 'username' => 'fake0', 'password' => Hash::make('password123'), 'full_name' => 'Fake0 Fakessex']];
     DB::table('users')->delete();
     foreach ($users as $user) {
         User::firstOrCreate($user);
     }
 }
 public function setUp()
 {
     parent::setUp();
     Route::enableFilters();
     // Authentication as super user.
     $user = User::firstOrCreate(['email' => 'quan@ll.com']);
     Auth::login($user);
 }
 public function setUp()
 {
     parent::setUp();
     // Authentication as super user.
     $user = User::firstOrCreate(array('email' => 'quan@ll.com'));
     Auth::login($user);
     $this->createLRS();
 }
 public function setUp()
 {
     parent::setUp();
     // Authentication as super user.
     $user = User::firstOrCreate(array('email' => $this->dummyEmail()));
     Auth::login($user);
     $this->lrs = $this->createLRS();
     $this->statement = App::make('Locker\\Repository\\Statement\\EloquentStatementRepository');
 }
Example #5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $faker = Faker\Factory::create();
     $u = User::firstOrCreate(['username' => 'admin', 'name' => 'The Admin', 'email' => 'admin@example.com', 'is_admin' => true]);
     $u->password = Hash::make('password');
     $u->save();
     $A = Area::firstOrCreate(['name' => 'Bodmin']);
     for ($i = 0; $i < 20; $i++) {
         Location::firstOrCreate(['name' => $faker->streetName, 'area_id' => $A->id]);
     }
 }
 /**
  * Get an existing user from the database or create a new one if one doesn't exist.
  *
  * @param array $userData
  * @return User
  */
 public function getOrCreate($userData)
 {
     $user = User::firstOrCreate(['email' => $userData['email']]);
     // Update the details on the record.
     $user->email = $userData['email'];
     $user->token = $userData['token'];
     $user->name = $userData['name'];
     $user->nickname = $userData['nickname'];
     $user->avatar = $userData['avatar'];
     $user->save();
     return $user;
 }
Example #7
0
 /**
  * @param $userData
  * @return static
  */
 public function findByUsernameOrCreate($userData)
 {
     $user = User::firstOrCreate(['username' => $userData->nickname]);
     // @todo: I don't think this will work. Let's handle it another way later...
     $email = $userData->email;
     if (!$email) {
         $email = $userData->nickname . '@users.noreply.github.com';
     }
     $user->email = $email;
     $user->name = $userData->name;
     $user->avatar = $userData->avatar;
     $user->token = $userData->token;
     $user->save();
     return $user;
 }
 public function setUp()
 {
     parent::setUp();
     Route::enableFilters();
     // Authentication as super user.
     $user = User::firstOrCreate(['email' => 'quan@ll.com']);
     Auth::login($user);
     $this->createLRS();
     $vs = array('actor' => array('objectType' => 'Agent', 'mbox' => 'mailto:duy.nguyen@go1.com.au', 'name' => 'quanvm'), 'verb' => array("id" => "http://adlnet.gov/expapi/verbs/experienced", "display" => array("und" => "experienced")), 'context' => array("contextActivities" => array("parent" => array("id" => "http://tincanapi.com/GolfExample_TCAPI", "objectType" => "Activity"), "grouping" => array("id" => "http://tincanapi.com/GolfExample_TCAPI", "objectType" => "Activity"))), "object" => array("id" => "http://tincanapi.com/GolfExample_TCAPI/Playing/Scoring.html", "objectType" => "Activity", "definition" => array("name" => array("en-US" => "Scoring"), "description" => array("en-US" => "An overview of how to score a round of golf."), 'type' => 'http://activitystrea.ms/schema/1.0/badge')), "authority" => array("name" => "", "mbox" => "mailto:quan@ll.com", "objectType" => "Agent"));
     $statement = App::make('Locker\\Repository\\Statement\\EloquentStatementRepository');
     $statement->create(array($vs), $this->lrs);
     $vs2 = $vs;
     $vs2['object']['definition']['type'] = 'http://activitystrea.ms/schema/2.0/badge';
     $statement2 = App::make('Locker\\Repository\\Statement\\EloquentStatementRepository');
     $statement2->create(array($vs2), $this->lrs);
 }
 /**
  * Process file import data into application data
  *
  * @return  void
  */
 private function processFileImport()
 {
     // Disable query log to conserve on memory
     DB::connection()->disableQueryLog();
     // Find first pending file import and eager load the csvRows
     $this->csv_import = CsvImport::where('status', 'pending')->with('csvRows')->first();
     if (!$this->csv_import) {
         printf("%s \n", "Nothing to process.");
         exit;
     }
     // Change the status of the import to avoid it being processed again.
     $this->csv_import->status = 'processing';
     $this->csv_import->save();
     if (count($this->csv_import->fileImportContent)) {
         // Get the header from the import
         $header = $this->csv_import->fileImportContent->first()->header;
         // Flip the values to keys and explode into array
         $header = array_flip(explode(',', $header));
         foreach ($this->csv_import->fileImportContent as $row) {
             // Convert the raw row data into array
             $row_array = explode(',', $row->content);
             // Build array of import properties
             $import_array = $header;
             // Match data array to the header array
             foreach ($import_array as $index => $key) {
                 $import_array[$index] = $row_array[$key];
             }
             /**
              * Here we can perform additional validation
              * for each data field and save it to the database
              */
             // Build array of parameters for our user import
             $user = User::firstOrCreate(['first_name' => $import_array['first_name'], 'last_name' => $import_array['last_name'], 'email' => $import_array['email']]);
             $movies = Movies::firstOrCreate(['user_id' => $user->id, 'movie_list' => $import_array['movies']]);
             $music = Music::firstOrCreate(['user_id' => $user->id, 'music_list' => $import_array['music']]);
         }
         $this->csv_import->status = 'processed';
         $this->csv_import->save();
     } else {
         $this->csv_import->status = 'error';
         $this->csv_import->save();
         //Log error
         exit;
     }
 }
Example #10
0
 public function setUp()
 {
     parent::setUp();
     $user = User::firstOrCreate(['email' => 'quan@ll.com']);
     //if first user, create site object
     if (\User::count() == 1) {
         $site = new \Site();
         $site->name = '';
         $site->description = '';
         $site->email = $user->email;
         $site->lang = 'en-US';
         $site->create_lrs = array('super');
         $site->registration = 'Closed';
         $site->restrict = 'None';
         //restrict registration to a specific email domain
         $site->domain = '';
         $site->super = array(array('user' => $user->_id));
         $site->save();
     }
 }
Example #11
0
 public function findByEmailIdorCreate($userData, $driver)
 {
     $fullName = explode(' ', $userData->getName());
     $firstName = array_shift($fullName);
     $lastName = implode(" ", $fullName);
     $user = User::firstOrCreate(['email' => $userData->email]);
     $user->firstName = $firstName;
     $user->lastName = $lastName;
     $user->avatar = $userData->getAvatar();
     if ($user->roleId == null) {
         $user->roleId = 2;
     }
     //2 = guest
     switch ($driver) {
         case 'facebook':
             $user->fbid = $userData->getId();
             break;
         case 'google':
             $user->gid = $userData->getId();
             break;
     }
     $user->save();
     return $user;
 }
Example #12
0
 public function personas($action)
 {
     if (isset($action)) {
         if ($action == "create") {
             $data = User::firstOrCreate(Input::all());
             return $respuesta = array('Record' => $data, 'Result' => "OK");
         }
         if ($action == "edit") {
             User::where("id", Input::get("id"))->update(Input::except("id"));
             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 == "residencia") {
             $nulos = DB::table('residencias')->select(DB::raw("'NO POSEE' as DisplayText, NULL as Value"));
             $respuesta = DB::table('residencias')->select("nombre as DisplayText", "id as Value")->union($nulos)->orderby('value', 'asc')->distinct()->get();
             return "var opciones=" . json_encode($respuesta);
         }
     }
 }
Example #13
0
 private function loginAndRedirect($user)
 {
     Auth::login(User::firstOrCreate(['username' => $user['userName'], 'phid' => $user['phid']]));
     Flash::success("Hello {$user['userName']}, you are now logged in!");
     return Redirect::to('/');
 }
Example #14
0
 public function RegisterWithGoogle()
 {
     $code = Input::get('code');
     $googleService = OAuth::consumer('Google');
     if (!empty($code)) {
         $token = $googleService->requestAccessToken($code);
         $result = json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
         $user = User::firstOrCreate(array('email' => $result['email']));
         if ($user != null) {
             $user->nombre = $result['name'];
             $user->avatar = $result['picture'];
             $user->save();
             Auth::login($user, false);
             Session::flash('message', "<img src='" . $user->avatar . "' height='70' alt=''> Registrado  con Facebook <br> Bienvenido " . $result['name']);
             if (Auth::user()->residencia_id == null) {
                 return Redirect::to("register/completar-registro");
             } else {
                 return Redirect::to("/");
             }
         } else {
             Session::flash('message', "Error al Crear usuario");
             return Redirect::to("/");
         }
     } else {
         $url = $googleService->getAuthorizationUri();
         return Redirect::to((string) $url);
     }
 }