Custom redirect after registration validation failure - Call to undefined method Illuminate\Http\RedirectResponse::validate()

Posted 4 months ago by Calid

I am using modal for registration and login, I want to redirect user to /registration page if validation has an error. I am getting an error

Call to undefined method Illuminate\Http\RedirectResponse::validate()

Here is my RegisterController.php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Foundation\Auth\RegistersUsers;

use Illuminate\Http\Request;

use Validator;
use Auth;

class RegisterController extends Controller

    use RegistersUsers;
    protected $redirectTo = '/home';

    public function __construct()

    protected function validator(array $data)
        $validator = Validator::make($data, [
            'username' => 'required|string|max:255',
            'email' => 'required|email|unique:users,email,'.Auth::id(),
            'password' => 'required|string|min:6',
            'country_id' => 'required|integer|exists:countries,id',
            'mobile' => 'required|numeric|min:6|max:15',
        //return $validator;
        if ($validator->fails()) {
            return redirect('/register')


    protected function create(array $data)
            $user = new User;
            $user->username = $data['username'];
            $user->email = $data['email'];
            $user->password = Hash::make($data['password']);
            $user->mobile = $data['email'];
            $user->country_id = $data['country_id'];
            $user->ip = request()->ip();

            if($user->save()) {
            return $user;


Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.