在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.如何重定向到其他页面?我是不是漏掉了什么。
发布于 2017-03-20 21:22:39
validator方法应该返回一个Validator。您看到的错误是因为您返回了一个重定向响应,一些代码假定您返回了一个Validator并在其上调用了$validator->validate()。
实际的调用可以在RegistersUsers性状中找到。
您需要抛出一个HttpResponseException。异常处理程序应该捕获它们并相应地呈现响应;在本例中,执行重定向。
https://stackoverflow.com/questions/42906165
复制相似问题