0

I want to save the uploads from the users in a path with the user ID. How can I integrate the ID into the path that automatically creates the folder?

if($r->hasFile('avatar'))

  {
    Auth::user()->update([
      'avatar'=> $r->avatar->store('public/$id/avatar')
    ]);
  }
slickness
  • 226
  • 4
  • 20

1 Answers1

2

You need double quotes if you want your id variable to be interpolated there:

'avatar'=> $r->avatar->store("public/$id/avatar")
mwal
  • 2,435
  • 22
  • 32
  • Then you can set it, earlier in your code, with `$id = Auth::id();`. But you might prefer `->store('public/' . Auth::id() . '/avatar/filename.jpg');` – mwal Nov 04 '17 at 17:08