/** * Run the database seeds. * * @return void */ public function run() { $user = User::find(1); if (!$user) { $user = factory('KnowTube\\User')->create(); } $category = Category::find(1); if (!$category) { $category = factory('KnowTube\\Category')->create(); } factory('KnowTube\\Resource')->create(['title' => 'good ol rick', 'url' => 'https://www.youtube.com/embed/dQw4w9WgXcQ', 'user_id' => $user->id, 'category_id' => $category->id]); factory('KnowTube\\Resource', 5)->create(['user_id' => $user->id, 'category_id' => $category->id]); }
/** * Obtain the user information from Google * * @return Response */ public function handleProviderCallback($provider) { $socialUser = Socialite::driver($provider)->user(); $nativeUser = User::firstOrNew(['email' => $socialUser->email]); $nativeUser = User::where('email', $socialUser->email)->first(); // if the user did not exist in the database save // register them. if ($nativeUser == null) { $nativeUser = new User(); $nativeUser->email = $socialUser->email; $nativeUser->name = $socialUser->name; $nativeUser->provider = $provider; $nativeUser->provider_id = $socialUser->id; $nativeUser->avatar = $socialUser->avatar; $nativeUser->save(); } elseif ($nativeUser->provider !== $provider) { // the user may already have an account but // is using the wrong provider. We hint at the // correct provider. return redirect()->action('Auth\\AuthController@getLogin')->with("message", "you originally registered with {$nativeUser->provider}!"); } Auth::login($nativeUser); return redirect('/'); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); }