You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've implemented the SluggableTrait on one of my classes and I wanted to dynamically get the reserved slugs using a closure, like so:
<?phpnamespaceProject\Page\Model;
useCviebrock\EloquentSluggable\SluggableInterface;
useCviebrock\EloquentSluggable\SluggableTrait;
classStaticPageextends \EloquentimplementsSluggableInterface
{
useSluggableTrait;
protected$sluggable = array(
'build_from' => ['title'],
'save_to' => 'slug',
'separator' => '-',
);
publicfunction__construct(array$attributes = array())
{
parent::__construct($attributes);
$this->sluggable['reserved'] = function() {
$result = [];
// ??? -> $$$return$result;
};
}
}
// And the following is added just so you can see it in action:$page = newStaticPage;
$page->title = 'About';
$page->sluggify();
Now, when trying to generate the slug, an UnexpectedValueException is thrown: Sluggable reserved is not null, an array, or a closure that returns null/array.
This happens because the class (or the trait) is namespaced, but the type checks (SluggableTrait line 57 and 87) say:
// check for reserved namesif ( $reserved instanceof Closure )
Thanks to PHP's namespaces, this should have been:
// check for reserved namesif ( $reserved instanceof \Closure )
I can submit a pull request with the fix for this, but I cannot provide unittests because I can't get them to work on my machine.
Cheers!
The text was updated successfully, but these errors were encountered:
I've implemented the SluggableTrait on one of my classes and I wanted to dynamically get the reserved slugs using a closure, like so:
['title'],
'save_to' => 'slug',
'separator' => '-',
);
public function __construct(array $attributes = array())
{
parent::__construct($attributes);
$this->sluggable['reserved'] = function() {
$result = [];
// ??? -> $$$
return $result;
};
}
```
}
// And the following is added just so you can see it in action:
$page = new StaticPage;
$page->title = 'About';
$page->sluggify();
Now, when trying to generate the slug, an UnexpectedValueException is thrown: Sluggable reserved is not null, an array, or a closure that returns null/array.
This happens because the class (or the trait) is namespaced, but the type checks (SluggableTrait line 57 and 87) say:
```
// check for reserved names
if ( $reserved instanceof Closure )
```
Thanks to PHP's namespaces, this should have been:
```
// check for reserved names
if ( $reserved instanceof \Closure )
```
I can submit a pull request with the fix for this, but I cannot provide unittests because I can't get them to work on my machine.
Cheers!
—
Reply to this email directly or view it on GitHub.
Hi,
I've implemented the SluggableTrait on one of my classes and I wanted to dynamically get the reserved slugs using a closure, like so:
Now, when trying to generate the slug, an UnexpectedValueException is thrown: Sluggable reserved is not null, an array, or a closure that returns null/array.
This happens because the class (or the trait) is namespaced, but the type checks (SluggableTrait line 57 and 87) say:
Thanks to PHP's namespaces, this should have been:
I can submit a pull request with the fix for this, but I cannot provide unittests because I can't get them to work on my machine.
Cheers!
The text was updated successfully, but these errors were encountered: