I'm doing the following in the
public function boot(DispatcherContract $events) { parent::boot($events); // set Tag slug Tag::saving(function($tag) { //slugify name $tag->slug = Str::slug($tag->name); }); }
When I run it in tinker, I get the following error:
PHP Fatal error: Class 'App\Providers\Str' not found in /var/www/questions-l5/app/Providers/EventServiceProvider.php on line 35
..but I don't know the Laravel way to import it. Do I need to just use use
, I tried to add the following to the config/app.php file:
'aliases' => [ ... 'Str' => 'Illuminate\Support\Str',
.. didn't seem to make much difference though.
http://chrishayes.ca/blog/code/laravel-4-generating-unique-slugs-elegantly http://laravel.com/api/5.0/Illuminate/Support/Str.html
Laravel Str slug() function generates a URL friendly slug from the given string.27-Mar-2021.
Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller (MVC) architectural pattern and based on Symfony.
I don't think you need to create alias here, so just add
use Illuminate\Support\Str;
to your model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With