public function postRegister(Request $request) { # Get the input from the registration form $userName = $request->input('user-name'); $password = $request->input('password'); $passwordConfirm = $request->input('password-confirm'); $email = $request->input('email-address'); $userExists = \p4\User::where('user_name', $userName)->orwhere('email', $email)->exists(); $input = array('email' => $email, 'password' => $password, 'password_confirmation' => $passwordConfirm, 'user_name' => $userName); $rules = ['user_name' => 'required|min:3|max:30|unique:users', 'email' => 'required|email|unique:users', 'password' => 'required|confirmed|min:6|max:20']; $validator = \Validator::make($input, $rules); if ($validator->fails()) { return redirect('Register')->withErrors($validator)->withInput(); } if (!$userExists) { # Register this User $newUser = \p4\User::create(['user_name' => $userName, 'password' => bcrypt($password), 'status' => 'A', 'email' => $email]); # Create Default My Feeds Category $default = new \p4\Category(); $default->user_id = $newUser->id; $default->name = "My Feeds"; $default->weight = 50; $default->save(); $message = "You have been registered. Please login to continue."; } return view('login', ['message' => $message]); }
/** * Return user if exists; create and return if doesn't * * @param $fbUser * @return User */ private function findOrCreateUser($fbUser) { //check if FB account already exists if ($authUser = User::where('facebook_id', $fbUser->id)->first()) { return $authUser; } //if FBUser's email is the same as an user's email account, directly log in as that user $user = User::where('email', $fbUser->email)->first(); if (sizeof($user) > 0) { //user account exists with same email addresss return $user; } return User::create(['name' => $fbUser->name, 'email' => $fbUser->email, 'facebook_id' => $fbUser->id]); }
/** * Run the database seeds. * * @return void */ public function run() { $kids = ['John' => ['Jill', 'Jamal', 'Jean'], 'Jasper' => ['Jean'], 'Olivia' => ['Jill', 'Jean'], 'Emily' => ['Jamal', 'Jean']]; # Now loop through the above array, creating a new pivot for each kid corresponding to user foreach ($kids as $name => $users) { # First get the kid name matched $kid = \P4\Kid::where('name', 'like', $name)->first(); # Loop through all users for each kid foreach ($users as $userName) { $user = \P4\User::where('name', 'like', $userName)->first(); # Save the kid's users info $kid->users()->save($user); } } }
/** * Run the database seeds. * * @return void */ public function run() { # First, create an array of all the users we want to associate kids with # The *key* will be the user email, and the *value* will be an array of tags. $users = ['*****@*****.**' => ['Julius', 'Pah'], '*****@*****.**' => ['Brett', 'Mary', 'Jus']]; # Now loop through the above array, creating a new pivot for each user to kid foreach ($users as $email => $kids) { # First get the user $user = \p4\User::where('email', 'like', $email)->first(); echo nl2br("user " . $user . "\n"); # Now loop through each kid for this book, adding the pivot foreach ($kids as $firstname) { echo nl2br("firstname " . $firstname . "\n"); $kid = \p4\Kid::where('firstname', 'LIKE', $firstname)->first(); # Connect this user to this kid $user->kids()->attach($kid); } } }