/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $user = User::find($id); if ($user->profile_id) { $profile = Profile::find($user->profile_id); } else { $profile = new Profile(); $profile->name = $user->name; $profile->pic = 'avatar3.png'; $profile->save(); $user->profile_id = $profile->_id; $user->save(); } return view('user.show')->with(['user' => $user, 'profile' => $profile]); }
public function compose(View $view) { $user = \Auth::user(); $view->with('user', $user); $profile_pic = 'avatar3.png'; if ($user->profile_id) { $view->with('profile_pic', \Gander\Profile::find($user->profile_id)->pic); } else { $view->with('profile_pic', $profile_pic); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(StoreProfileRequest $request) { $profile_pic = 'avatar3.png'; if (\Input::file('image')->isValid()) { $destinationPath = public_path('img/'); // upload path $extension = \Input::file('image')->getClientOriginalExtension(); // getting image extension $fileName = rand(11111, 99999) . '.' . $extension; // renameing image \Input::file('image')->move($destinationPath, $fileName); // uploading file to given path $profile_pic = $fileName; } $profile = new Profile(); $profile->name = $request->name; $profile->pic = $profile_pic; $profile->save(); $user = \Auth::user(); $user->profile_id = $profile->_id; $user->save(); return redirect('profile'); }