예제 #1
0
 protected function saveFile(UploadedFile $file)
 {
     $upload_dir = public_path('img/avatar');
     $file_name = 'images-' . date('dmY-His') . '.' . $file->getClientOriginalExtension();
     try {
         if ($file->move($upload_dir, $file_name)) {
             $file = new File();
             $file->setAttribute('name', $file_name);
             $file->setAttribute('path', $upload_dir);
             $file->save();
             return $file->id;
         } else {
             return null;
         }
     } catch (\Exception $ex) {
         return abort(500, $ex->getMessage());
     }
 }