예제 #1
0
 /**
  * Delete the media from the database and from the server.
  * @return bool
  * @throws \Exception
  */
 public function delete()
 {
     // Delete any files, including sizes.
     try {
         if ($this->sizes) {
             foreach ($this->sizes as $key => $url) {
                 unlink($this->path($key));
             }
         }
         unlink($this->path());
     } catch (\ErrorException $e) {
         // File probably doesn't exist, so delete anyway.
     }
     Relationship::clear($this);
     return parent::delete();
 }
예제 #2
0
 /**
  * Find related child objects of this model.
  * @param $child string|Model
  * @return Collection
  */
 public function related($child)
 {
     return Relationship::collection($this, $child);
 }
예제 #3
0
 /**
  * Relate an object to a child object.
  * @param Model $parent
  * @param Model $child
  * @return static
  */
 public static function relate(Model $parent, Model $child)
 {
     return Relationship::create(['parent_id' => $parent->id, 'child_id' => $child->id, 'parent_object' => $parent->getClass(), 'child_object' => $child->getClass(), 'priority' => Relationship::lastPriority($parent, $child)]);
 }