Guest User

Untitled

a guest
Feb 15th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. trait FileSaver {
  2. /**
  3. * @param $file
  4. * @return string
  5. */
  6. public function setFileAttribute($file)
  7. {
  8. if ($file instanceOf UploadedFile) {
  9.  
  10. $fileNameWithExt = $file->getClientOriginalName();
  11. $filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
  12. $extension = $file->getClientOriginalExtension();
  13. $fileNameToStore = $filename . '_' . time() . '.' . $extension;
  14.  
  15. $file->storeAs($this->file_path, $fileNameToStore);
  16.  
  17. return $this->attributes['file'] = $fileNameToStore;
  18. }
  19. }
  20. }
Add Comment
Please, Sign In to add comment