public function show(SS_HTTPRequest $r) { $presentation = Sluggable::get_by_slug('SchedPresentation', $r->param('ID')); if (!$presentation) { return $this->httpError(404); } return array('Presentation' => $presentation); }
/** * @param \Laravel\Database\Eloquent\Model $model The model that needs to be sluggified. * @param bool $force Force the model to generate a new slug, usefull if 'on_update' needs to bypassed. Defaults to false. * @param array $objects An array of {@link \Laravel\Database\Eloquent\Model} objects which the slug should be tested against, this defaults to null in which case Sluggable will check the database to determine the slug. */ public static function make($model, $force = false, $objects = null) { $class = get_class($model); // If the class has no sluggable configuration, there is nothing to be done so we stop. if (!isset($class::$sluggable)) { return; } $instance = new Sluggable($model); // Check if the model is going to be created or updated, if it's going to update // and 'on_update' is false we can stop, unless we forced the update with the force parameter. if ($model->exists && $instance->configuration['on_update'] == false && !$force) { return; } // Create the slug $slug = $instance->slug(); // Check if the slug is already present and weither we want to have unique slugs if (($object = $instance->exists($slug, $objects)) && $instance->configuration['unique']) { // If the slug exists, we get the next available slug $slug = $instance->next($slug, $object); } // We set the 'save_to' field of the model to the newly created slug, yeah! $model->{$instance->configuration['save_to']} = $slug; }
public function testMultipleBuildFrom() { $class = get_class($this->model); $class::$sluggable['build_from'] = array('title', 'other_title_field'); Sluggable::make($this->model, false, array()); $this->assertEquals("this-is-a-test-this-is-another-test", $this->model->slug); $class::$sluggable['build_from'] = 'title'; }