Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait FileSaver {
- /**
- * @param $file
- * @return string
- */
- public function setFileAttribute($file)
- {
- if ($file instanceOf UploadedFile) {
- $fileNameWithExt = $file->getClientOriginalName();
- $filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
- $extension = $file->getClientOriginalExtension();
- $fileNameToStore = $filename . '_' . time() . '.' . $extension;
- $file->storeAs($this->file_path, $fileNameToStore);
- return $this->attributes['file'] = $fileNameToStore;
- }
- }
- }
Add Comment
Please, Sign In to add comment