Reputation: 402
using laravel 5.6 and in my controller I have following code,
$input = $request->all();
$validator = $this->validator($input);
if ($validator->passes()){
$booking = $this->create($input)->toArray();
$booking['link'] = str_random(30);
DB::table('activations')->insert(['id_user' => $booking['id'], 'token' => $booking['link']]);
Mail::send('mail.activation', $booking, function($message) use ($booking) {
$message->to($booking['email']);
$message->subject('acxian.com - Activation Code');
});
but when I try submit button following error is occurring,
1/1) BadMethodCallException
Method [validator] does not exist.
how can I fix this?
Upvotes: 0
Views: 493
Reputation: 2604
There is no validator
method in laravel controllers. To fix this error you can define it by yourself in controller like this:
protected function validator($input){
return Validator::make($input, [
//array with validation rules
]);
But the best way to validate form data is using form request object. Read this for more details: https://laravel.com/docs/5.6/validation#form-request-validation
Upvotes: 1