I have a table states and fields are id,country_id,state_code,state_name.Now I want to validate that same country doesn't have a same state_code and same state_name in a table.
I tried but it's not working.
In my Controller :
$validator = State::validator($request->all(), $id);
if ($validator->fails()) {
return redirect()->back()
->withErrors($validator->getMessageBag())
->withInput($request->all());
}
Here is my validation function in model :
protected function validator(array $data, $id)
{
return Validator::make($data, [
'country_id' => 'required',
'state_code' => 'required',
'state_name' => 'required',
]);
}
How can I solved this without custom validation ?
state_codeandstate_name? I would think thatstate_codewould be unique enough on its own, and you shouldn't have to worry aboutstate_name.Romania,stateGorjhas same codeGJforGujaratstateslugcolumn, which is a lower-cased,-separated string of "unique" parts, likero-gj-gorjandro-gj-gurarat; constructed fromcountry_code,state_code,state_name, and check uniqueness of that.