How to create unique slug in laravel and validate them ?
Here is my validation code:
$this->validate($request,[
'company_name' => 'required|unique:admin_users,company_name,slug|max:191',
]);
Here is my slug code:
$db_filed->company_name = str_slug($request->company_name, '-');
Thanks.
you can create the slug inside your controller probably inside the store function like this
Setup a FormRequest to do the validation for the route with the rules like this:
https://laravel.com/docs/5.4/validation#form-request-validation
Or you need to create the slug before assigning it to the company name.
https://laravel.com/docs/5.4/validation#manually-creating-validators
I'm trying this way and now it's work,
Here is code form:
Here is controller code: