I have this function where I want to update user background image so I write:
public function updateBg(Request $request)
{
$user = Auth::user();
$this->validate($request, [
'background' => 'image|max:10000',
// validate also other fields here
]);
// checking file is valid.
if (!$request->file('background')->isValid()) return redirect()->back()->withErrors(["background" => "File is corrupt"]);
// file is valid
$destinationPath = public_path().'/images/Custaccounts/'.$user->id; // upload path
$extension = $request->file('background')->getClientOriginalExtension(); // getting image extension
$ran = str_random(5);
$photo = $ran.'.'.$extension;
$request->file('background')->move($destinationPath, $photo); // uploading file to given path
$bg = $user->id.'/'.$photo;
dd($bg);
$user->update(['background' => $bg]);
return Redirect::back();
}
this line wont work: $user->update(['background' => $bg]);
dd($bg) give me right string and image is uploaded just I cant update my 'background; field ...
also when I write:
$user->update(['background' => $bg, 'name'=>'John']);
name is updated but background not... at user model background field is fillable of cource
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire