06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Filesystem / Cloud Storage 361<br />

11 /**<br />

12 * Update the avatar for the given user.<br />

13 *<br />

14 * @param Request $request<br />

15 * @param int $id<br />

16 * @return Response<br />

17 */<br />

18 public function updateAvatar(Request $request, $id)<br />

19 {<br />

20 $user = User::findOrFail($id);<br />

21<br />

22 Storage::put(<br />

23 'avatars/'.$user->id,<br />

24 file_get_contents($request->file('avatar')->getRealPath())<br />

25 );<br />

26 }<br />

27 }<br />

When using multiple disks, you may access a particular disk using the disk method on the Storage<br />

facade. Of course, you may continue to chain methods to execute methods on the disk:<br />

1 $disk = Storage::disk('s3');<br />

2<br />

3 $contents = Storage::disk('local')->get('file.jpg')<br />

Retrieving Files<br />

The get method may be used to retrieve the contents of a given file. The raw string contents of the<br />

file will be returned by the method:<br />

1 $contents = Storage::get('file.jpg');<br />

The exists method may be used to determine if a given file exists on the disk:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!