protected function afterSaving($request) { if (!in_array('LiveCMS\\Models\\Contracts\\UserOnlyInterface', class_implements($this->model))) { if ($request->has('permalink')) { $permalink = $this->model->permalink; if ($permalink == null) { $permalink = new Permalink(); $permalink->postable()->associate($this->model); } $permalink->permalink = $request->get('permalink'); $permalink->save(); } else { if ($this->model->permalink) { $this->model->permalink->delete(); } } } if ($request->hasFile('picture') && $request->file('picture')->isValid()) { $object = $this->model; Upload::setFilenameMaker(function ($file, $object) { $title = $object->title ? $object->title : $object->name; return str_limit(str_slug($title . ' ' . date('YmdHis')), 200) . '.' . $file->getClientOriginalExtension(); }, $object); Upload::model($object); $this->model->save(); } if (empty($this->model->status)) { $status = Model::STATUS_DRAFT; $this->model->update(compact('status')); } return parent::afterSaving($request); }
public function getByPermalink($permalink) { $page = Permalink::where('permalink', $permalink)->firstOrFail(); $type = (new ReflectionClass($post = $page->postable))->getShortName(); return view()->exists(theme('front', $permalink)) ? view(theme('front', $permalink), compact('post')) : $this->{'get' . $type}(false, $post->slug); }