コード例 #1
0
 /**
  * Add if missing, else update
  * @param array $data
  */
 public function createOrUpdate($data)
 {
     // Try to get the gallery
     $gallery = Media::where('type', 'collection')->where('parent_id', null)->where('entry_id', array_get($data, 'entry_id'))->where('field_id', array_get($data, 'field_id'))->first();
     // Create or update
     if ($gallery) {
         return $this->update($gallery->id, $data);
     } else {
         return $this->create($data);
     }
 }
コード例 #2
0
ファイル: MediaDbRepository.php プロジェクト: creolab/krustr
 /**
  * Delete media item
  * @param  integer $id
  * @return boolean
  */
 public function destroy($id)
 {
     $media = $this->find($id);
     if ($media) {
         // Get absolute path
         $path = public_path(trim($media->path, '/'));
         if (File::exists($path)) {
             // We also need to find all resized images to clean everything up
             $this->deleteResized($path);
         }
         // Delete from database
         Media::destroy($id);
         return true;
     }
 }