Skip to content

Commit

Permalink
Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
drobee committed Jul 21, 2019
1 parent a691c4c commit fb790ac
Showing 1 changed file with 39 additions and 33 deletions.
72 changes: 39 additions & 33 deletions src/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,49 @@ class Slug extends Field
'event' => 'keyup',
];

public function __construct($name, $attribute = null, callable $resolveCallback = null)
{
$this->withMeta(['options' => $this->options]);
parent::__construct($name, $attribute, $resolveCallback);
}

public function slugModel(string $model): Element
{
return $this->withMeta(['model' => $model]);
}

public function slugUnique(): Element
{
return $this->setOption('generateUniqueSlugs', true);
}

public function slugMaxLength(int $length): Element
{
return $this->setOption('maximumLength', $length);
}

public function slugSeparator(string $separator): Element
{
return $this->setOption('slugSeparator', $separator);
}

public function slugLanguage(string $language): Element
{
return $this->setOption('slugLanguage', $language);
}

public function event(string $eventType): Element
{
if (in_array($eventType, ['keyup', 'blur'])) {
return $this->setOption('event', $eventType);
}

return $this->setOption('event', 'keyup');
}

protected function setOption(string $name, string $value): Element
{
$this->options[$name] = $value;
return $this->withMeta(['options' => $this->options]);
}
{
return $this->setOption('generateUniqueSlugs', true);
}

public function slugMaxLength(int $length): Element
{
return $this->setOption('maximumLength', $length);
}

public function slugSeparator(string $separator): Element
{
return $this->setOption('slugSeparator', $separator);
}

public function slugLanguage(string $language): Element
{
return $this->setOption('slugLanguage', $language);
}

public function event(string $eventType): Element
{
if (in_array($eventType, ['keyup', 'blur'])) {
return $this->setOption('event', $eventType);
}

return $this->setOption('event', 'keyup');
}

protected function setOption(string $name, string $value): Element
{
$this->options[$name] = $value;
return $this->withMeta(['options' => $this->options]);
}
}

0 comments on commit fb790ac

Please sign in to comment.