@oussamamater Yes it does the trick and slug-fy my string but if I have the same slug in database it doesn't work. It creates the same slug and I end up with the same url for 2 products. I didn't provide any errors because there isn't any. The only error I get is something silly I tried but It's the reason why It made me chase an answer instead of using any package.
So I was trying to make a rule where a product can't have same slug in the same shop. So I ended up doing this in my products migration file.
$table->unique(['slug', 'webshop_id'], 'slug_webshop_unique');
I want to say that a shop can't have a product with the same slug. And then I went on searching on how to make the slug change itself when it find another slug with the same slug value.
So I stumbled on this thread.
To summerize, It should do something like this i-am-a-unique-slug and the second slug with the same slug value would be i-am-a-unique-slug-1 and so on.
@tykus Said that Illuminate/Support/Str was never responsible for achieving this but the error I got is the reason why I wasted hours instead of using a package to solve my issue :(
Integrity constraint violation: 1062 Duplicate entry 'my-first-title-1' for key 'products.slug_webshop_unique' (SQL: insert into `products` (`user_id`, `webshop_id`, `category_id`, `main_thumbnail`, `title`, `slug`, `price`, `currency`, `type`, `desc`, `qty`, `updated_at`, `created_at`) values (1, 1, ?, thumbnails/25igqD5KJeqItGI4CqlPJhDM6kK66jD0edS2dDje.jpg, my first title, my-first-title, 12, usd, physicalProd, ?, ?, 2022-09-05 18:53:05, 2022-09-05 18:53:05))
As You can see the my-first-title-1 is right there because another product has the same slug, but for some reasone the SQL query trying to insert the normal slug.
trying to Str::slug($validated['title'], '-') gets me the normal slug not the modified slug.