Why do something like this:
Route::get('post/{username}/{post_title}');
Are you asking me why? That's what I am doing. That's why the post_title needs to only be unique to the username, not table wide.
then every post must be assigned to a single username/user_id
If yout think about validating the uniqueness of the username / slug combination, you can pass additional parameters to the unique rule. Thats explained with more details in the docs.
'unique:users,' . $username . ',NULL,id,slug,' . $slug
If its not for validating a form I don't know anyway of doing it except running a query.
And laravel already have a slug generator : Str::slug(); :)
laravel already have this helper included with Str facade . try this : Str::slug('your string');
My eloquent-sluggable package may be of help. It won't do what you need out of the box, but you could overload the method to check for uniqueness with your own logic, and you should be good to go. Open an issue if you need some more help.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community