1

I am trying to do registration of multi-user in my registration controller and used the following code and checked. But it shows me error:

Method App\Http\Controllers\Auth\RegisterController::validator does not exist.

<?php namespace App\Http\Controllers\Auth; use App\Admin; use App\Manager; use App\Http\Controllers\Controller; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Http\Request; class RegisterController extends Controller { use RegistersUsers; public function __construct() { $this->middleware('guest'); $this->middleware('guest:admin'); $this->middleware('guest:manager'); } protected function createAdmin(Request $request) { $this->validator($request->all())->validate(); $admin = Admin::create([ 'name' => $request['name'], 'email' => $request['email'], 'password' => Hash::make($request['password']), ]); return redirect()->intended('login/admin'); } protected function createManager(Request $request) { $this->validator($request->all())->validate(); $manager = Manager::create([ 'name' => $request['name'], 'email' => $request['email'], 'password' => Hash::make($request['password']), ]); return redirect()->intended('login/manager'); } } 
1
  • do you have a function validator() in your RegisterController class? Commented May 17, 2019 at 5:40

1 Answer 1

3

Try to add validator() function like follow:

protected function validator(array $data, $table) { return Validator::make($data, [ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'max:255', 'unique:'.$table], 'password' => ['required', 'string', 'min:8', 'confirmed'], ]); } 

then you can make validation like so:

$this->validator($request->all(), 'table_name')->validate(); 

change table_name with corresponding name.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks it works! However I am encountering another problem when doing multi-auth. Now when i submit the registration it shows me: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'bvend.users' doesn't exist. Though i have no users table, instead I have admins table
@WahidSherief change 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], to 'email' => ['required', 'string', 'email', 'max:255', 'unique:admins'],
@WahidSherief You're getting this error because validator is looking for users table's email column to check for email if it already exists

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.