Level 102
Here you are using request as a variable (you do it multiple places)
($request()->hasFile('avatar')) //before
(request()->hasFile('avatar')) //after
1 like
I am getting undefined variable request when trying to add an upload function to UpdateUserProfileInformation.php Laravel Fortify.
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
{
/**
* Validate and update the given user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
*/
public function update($user, array $input)
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'email',
'max:255',
'address'=>['required','string','max:255'],
'city' => ['required', 'string', 'max:255'],
'state' => ['required', 'string', 'max:255'],
'zipcode' => ['required', 'string', 'max:255'],
'homephone' => ['required', 'string', 'max:255'],
'cellphone' => ['required', 'string', 'max:255'],
// 'avatar' => ['mimes:jpg,jpeg,png,gif','max:4096'],
Rule::unique('users')->ignore($user->id),
],
])->validateWithBag('updateProfileInformation');
if ($input['email'] !== $user->email &&
$user instanceof MustVerifyEmail) {
$this->updateVerifiedUser($user, $input);
} else {
if ($request()->hasFile('avatar')) {
$image = $request()->file('avatar');
$filename = time() .'.'. $image->getClientOriginalExtension();
$path = public_path('dashboard/images/profile/');
Image::make($image)->save($path.$filename);
if ($user->image !== 'default.png') {
File::delete($path.$user->avatar);
}
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'address' => $input['address'],
'city' => $input['city'],
'state' => $input['state'],
'zipcode' => $input['zipcode'],
'homephone' => $input['homephone'],
'cellphone' => $input['cellphone'],
'avatar' => $user->avatar = $filename,
])->save();
alert()->success('Profile Updated','User Profile Updated Successfully!!!');
}
}
}
/**
* Update the given verified user's profile information.
*
* @param mixed $user
* @param array $input
* @return void
*/
protected function updateVerifiedUser($user, array $input)
{
if ($request()->hasFile('avatar')) {
$image = $request()->file('avatar');
$filename = time() .'.'. $image->getClientOriginalExtension();
$path = public_path('dashboard/images/profile/');
Image::make($image)->save($path.$filename);
if ($user->image !== 'default.png') {
File::delete($path.$user->avatar);
}
$user->avatar = $filename;
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'address' => $input['address'],
'city' => $input['city'],
'state' => $input['state'],
'zipcode' => $input['zipcode'],
'homephone' => $input['homephone'],
'cellphone' => $input['cellphone'],
'avatar' => $user->avatar = $filename,
])->save();
alert()->success('Profile Updated','User Profile Updated Successfully!!!');
$user->sendEmailVerificationNotification();
}
}
}
@artisticre not really related to the original issue. But perhaps your column is avatar, not image?
if ($user->image !== 'avatar.png') {
if ($user->avatar !== 'avatar.png') {
Please or to participate in this conversation.