Answer the question
In order to leave comments, you need to log in
Where do you store helper functions in Laravel?
There is the following
$validator = Validator::make($request->all(), [
'page' => 'integer|required',
'per_page'=> 'integer|required'
]);
if($validator->fails()){
return $validator->errors()->all();
}
class valid{
check($validate, $req){
$validator = Validator::make($req, $validate);
if($validator->fails()){
return $validator->errors()->all();
}
}
}
$valid->check(['page' => 'integer|required','per_page'=> 'integer|required'], $request->all());
Answer the question
In order to leave comments, you need to log in
For Laravel 5, it makes no sense to use a separate class for validation (as it was in L4).
In L5, there is a ValidatesRequests trait that can be used in controllers, and that's when the validate method comes in.
Better yet, use a custom FormRequest class to validate the data.
That is, we create the Http\Requests\UpdateUserProfile class and inherit it from Request.
In UpdateUserProfile we write 2 methods:
// Проверяем может ли пользователь делать это действие
public function authorize();
// Возвращаем массив с правилами
public function rules();
Write in composer
"files": [
"app/helpers.php"
]
composer dumpautoload
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question