public function setSlugAttribute($value) { $slug = \Jarboe::urlify($value); $slugs = $this->where('parent_id', $this->parent_id)->where('id', '<>', $this->id)->whereRaw("slug REGEXP '^{$slug}(-[0-9]*)?\$'")->lists('slug'); $slugCount = ''; if ($slugs) { $slugCount = 0; foreach ($slugs as $existedSlug) { preg_match('~(\\d+)$~', $existedSlug, $matches); if (isset($matches[1])) { $slugCount = $slugCount > $matches[1] ? $slugCount : $matches[1]; } } $slugCount++; } $slug = $slugCount ? $slug . '-' . $slugCount : $slug; $this->attributes['slug'] = $slug; }
protected function handleFileUpload() { // FIXME: $file = Input::file('file'); if ($this->controller->hasCustomHandlerMethod('onFileUpload')) { $res = $this->controller->getCustomHandler()->onFileUpload($file); if ($res) { return $res; } } $extension = $file->getClientOriginalExtension(); $fileName = time() . '_' . \Jarboe::urlify($file->getClientOriginalName()) . '.' . $extension; $definitionName = $this->controller->getOption('def_name'); $prefixPath = 'storage/tb-' . $definitionName . '/'; $postfixPath = date('Y') . '/' . date('m') . '/' . date('d') . '/'; $destinationPath = $prefixPath . $postfixPath; $status = $file->move($destinationPath, $fileName); $data = array('status' => $status, 'link' => URL::to($destinationPath . $fileName), 'short_link' => $destinationPath . $fileName); return Response::json($data); }
function urlify($string) { return Jarboe::urlify($string); }
public function getSlug() { return Jarboe::urlify(strip_tags($this->title)); }