public function update() { $inline = Inline::find($this->params()->id); if (!current_user()->has_permission($inline)) { $this->access_denied(); return; } $inline->updateAttributes($this->params()->inline); $images = $this->params()->image ?: []; foreach ($images as $id => $p) { $image = InlineImage::where('id = ? AND inline_id = ?', $id, $inline->id)->first(); if (isset($p['description'])) { $image->description = $p['description']; } if (isset($p['sequence'])) { $image->sequence = $p['sequence']; } if ($image->changedAttributes()) { $image->save(); } } $inline->reload(); $inline->renumber_sequences(); $this->notice('Image updated'); $this->redirectTo(['#edit', 'id' => $inline->id]); }
public function delete_file() { # If several inlines use the same image, they'll share the same file via the MD5. Only # delete the file if this is the last one using it. $exists = InlineImage::where('id <> ? AND md5 = ?', $this->id, $this->md5)->first(); if ($exists) { return; } if (is_file($this->file_path())) { unlink($this->file_path()); } if (is_file($this->preview_path())) { unlink($this->preview_path()); } if (is_file($this->sample_path())) { unlink($this->sample_path()); } }