X
X
Xveeder2018-04-11 11:57:32
Laravel
Xveeder, 2018-04-11 11:57:32

What's wrong with Laravel validation?

There is a controller:

<?php

namespace App\Http\Controllers\CAuth;

use  App\Http\Classes\UserRegister;
use Illuminate\Http\Request;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

class CustomAuthController {
    public function validate (Request $request) {
        $rules = [
            'username' => 'required|string|max:255',
            'email' => 'required|string|email|max:255',
            'password' => 'required|string|min:6',
            'invite' => 'required|integer|min:6',
        ];
            
       $this->validate($request, $rules);       
     
    }
}

The data is transferred from the form via a POST request, and the POST request is also registered in the routes. But after processing this controller, the browser crashes:
5acdcdea8bedc775786117.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arman, 2018-04-11
@Arik

Is this in production? logs are silent? if dev then turn on error display.
so anything can be, what kind of middleware do not let through.. offhand maybe in csrf fields?

K
Konstantin B., 2018-04-11
@Kostik_1993

What were you expecting when you called the validate method?
Pay attention, your controller method is also called the validation method in the controller, which, by the way, you also call from your method
Replace with another name, it should be either store or update Oh yeah, and you don’t inherit your controller from the base one, in this is also a problem

I
iljaGolubev, 2018-04-11
@iljaGolubev

Must be

class CustomAuthController {
    public function validate (Request $request) {
        $rules = [
            'username' => 'required|string|max:255',
            'email' => 'required|string|email|max:255',
            'password' => 'required|string|min:6',
            'invite' => 'required|integer|min:6',
        ];

       // Внимание
       $request->validate($rules);            
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question