cviebrock / eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel
MIT License
3.91k stars 461 forks source link

Feature/custom method array call #584

Closed mohamadtsn closed 2 years ago

mohamadtsn commented 2 years ago

To make a slug, you can use special methods and change its process. A Closure must be received to change this process. Also, Closure can be defined in config/sluggable.php file. Now the issue and the problem it causes is that when we want to cache the config files using config:cache command during the program execution in production mode. This is exactly the problem and the reason is that Closures cannot be cached.

I hope I have contributed in a positive way to this practical package :shipit: Thank you!

cviebrock commented 2 years ago

I like this ... except I think a simpler solution might be to change these lines in the existing code:

} elseif (is_callable($method)) {
    $slug = $method($source, $separator);

to this:

} elseif (is_callable($method, true, $callable)) {
    $slug = $callable($source, $separator);
cviebrock commented 2 years ago

Actually ... ignore my previous comment. The package already works using an array as the method in config.

I tested by adding just your test files to the 9.0.0 version of the package and running the tests. They pass just fine.