Answer the question
In order to leave comments, you need to log in
How to add custom validation to Request Laravel?
Hello, I apologize in advance for a possibly stupid question, I'm just not good at it. The essence of the question is that I want to check for example: the car already has a steering wheel, for example, and you don’t need to immediately assign a new steering wheel to the database, you first need to remove the installed steering wheel, I want to display a message that the steering wheel is already available, through the controller wrote a simple working code (which I also simplified, because in the full version there is a check that the steering wheel is not a consumable :)):
$auto = $request->get('auto_id');
if ($auto != "" ){
$dubl=Spare::where([
['auto_id' , '=' , $auto]
])->first();
}
if(!isset($dubl->id)||($dubl->id="")){
$variable->save();
}else{
return response()->json('duble');
}
Answer the question
In order to leave comments, you need to log in
$messsages = array(
//mesages
);
$rules = array(
//rules
);
$v = Validator::make($request->all(), $rules, $messsages);
$v->sometimes('pole_id','unique:table,pole_id',function ($input) {
//check
});
$v->validate();
$new = Table::create($v->validated());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question