So, I’m trying to make update function, using this
public function editProfile(Request $request, $id)
{
// Validating
$request->validate([
// 'username' => 'nullable|unique:users|min:4',
// 'email' => 'nullable|unique:users|email:rfc,dns',
'contact_phone' => 'nullable|digits_between:9,12',
'bio_en' => 'nullable',
'bio_ar' => 'nullable',
'icon' => 'nullable',
'logo' => 'nullable',
'plan_id' => 'required',
'category_id' => 'required',
'is_local' => 'required',
]);
$user = User::find($id);
$user->update([
'username' => $request->username,
'email' => $request->email,
'contact_phone' => $request->contact_phone,
'bio_en' => $request->bio_en,
'bio_ar' => $request->bio_ar,
'logo' => $request->logo,
'icon' => $request->icon,
'plan_id' => $request->plan_id,
'category_id' => $request->category_id,
'referred_by_id' => Auth::user()->id,
]);
if ($user) {
return back()->with("success", __("editedSuccessfully"));
} else {
return back()->with('error', __("somethingWentWrongTryAgainLater"));
}
}
}
but I get the error
Call to a member function update() on null
shows on line $user->update
hope anyone can help me