Category: Laravel

first let me tell you a little bit about slug if you are building a website its good practice specially in terms of SEO to use slug for your website pages instead of post id or something like that so now you should all know what is slug laravel itself supports slugs and have a function to build slugs ( remove spaces and illegal characters) Str::slug(); and if you are on older versions of laravel you should have it as a helper method str_slug() but but if you want to be efficient and don't reinvent the wheel its almost always a good idea to use library's . i ll go with cviebrock here and now we just need to add the trait to our model and its done . it will automatically create slug every time new record is creating you just say where should it get the text and it will do the rest for you.

what i wanted to do was to pass the slug for the post as slug so its formatted correctly before save.

the sluggable method is required by package but as you may have noticed there is no need to fill the config in it as we are doing the work ourselves.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners