我尝试在mobile_no
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use App\User;
use App\Http\Controllers\Controller;
class RegisterController extends Controller
{
use RegistersUsers;
protected function validator(array $data){
$validator = Validator::make($data, $rules, $messages);
// If unique validation fails
if($validator->fails()){
$failed = $validator->failed();
// if failed because unique mobile number validation rule
if(count($failed) == 1){
foreach ($failed as $key => $value) {
if($key == 'mobile_no'){
if(count($value) == 1 && isset($value['Unique'])){
return redirect('/verify');
}
}
}
}
return redirect('/somepage');
}
return $validator;
}
}
当我尝试这样做时,它会给出错误
BadMethodCallException in RedirectResponse.php line 218:
Method [validate] does not exist on Redirect.
如何重定向到其他页面?我错过了什么。
答案 0 :(得分:1)
validator
方法应返回Validator。您看到的错误是因为您返回了Redirect响应,而某些代码假定您返回Validator并在其上调用$validator->validate()
。
实际通话可在RegistersUsers trait。
中找到您需要抛出HttpResponseException。您的异常处理程序应捕获这些并相应地呈现响应;在这种情况下执行重定向。