/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(StoreNewPhotoRequest $request) { $data = $request->only(['name', 'url']); $photo = new Photo(); $photo->user_id = Auth::user()->id; $photo->name = $data['name']; $photo->url = $data['url']; $photo->save(); return $this->response->collection(Auth::user()->photos, new PhotoTransformer()); }
public function githubCallback() { $githubUser = Socialite::driver('github')->scopes(['gist'])->user(); $user = JWTAuth::setToken(Session::get('token'))->authenticate(); $personalInfo = PersonalInformation::where('user_id', '=', $user->id)->first(); $photo = Photo::where('user_id', '=', $user->id)->where('name', '=', 'Github')->first(); $client = new Client(); $response = $client->request('GET', $githubUser->avatar); $body = $response->getBody(); if ($photo == null) { $ph = new Photo(); $ph->name = 'Github'; $ph->url = base64_encode($body); $ph->user_id = $user->id; $ph->enabled = false; $ph->save(); } if ($personalInfo != null) { // update the information $personalInfo->first_name = $githubUser->user['name']; $personalInfo->email = $githubUser->user['email']; $personalInfo->bio = $githubUser->user['bio']; $personalInfo->save(); } else { // create it $pi = new PersonalInformation(); $pi->user_id = Auth::user()->id; $pi->first_name = $githubUser->user['name']; $pi->email = $githubUser->user['email']; $pi->bio = $githubUser->user['bio']; $pi->save(); } $view = View::make('welcome'); $view->script = 'window.close();'; return $view; }