when you first transfer from thinkphp5.1 to laravel, for form validation, there are two ways to look at the document:
the first is to use the following code directly in the controller
$this->validte(request(),$rule)
the second is
Validate::make(request()->all(),$rule);
but there is a difference between the two. The first one can keep the page on the submission page after the validation error is found, and the error message can be displayed directly through the following code
@if(count($errors)>0)
<div class="alert alert-danger" role="alert">
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</div>
@endif
but the second goes directly to the form submission method, and the page jumps.
because I need it, I rewrite the verification layer, but I don"t want to inherit the Controller class. I use the following method to handle validation:
class Validate
{
protected $rule=[];
protected $message=[];
protected $sence=[];
protected $input;
private $validator;
final public function check($input,$senceName=null){
$this->input=$input;
.....
$this->validator=Validator::make($input,$rule,$message);
/*,*/
if($this->validator->fails()){
return back()->withErrors($this->validator)
->withInput();
}
return true;
}
the problem mainly lies in the code where the verification failed, how to achieve the effect of the first kind of verification, and how my code needs to be modified.
there is another problem. Just transferred from the tp framework, I used to find a method in a class that can be found directly with the ctrl+ left button in phpstorm.
but I can never find this method in laravel. For example, the valiate function in the first controller base class, how can I find the source code of this function? how can laravel find the corresponding function quickly?
ask for your advice, thank you very much