我正在拉拉维尔项目中工作,我正在使用js验证器来验证表单文件,但是如果我使用验证规则,则同样不起作用。我希望提交唯一身份的电子邮件。如果我使用它,我将无法提交表格本身。所有其他验证规则都正常工作。unique:users请帮我找出问题以下是用户控制器中的代码,我应用了验证规则<?phpnamespace App\Http\Controllers;use App\Http\Controllers;use Illuminate\Http\Request;use JsValidator;use Validator;use App\User;use Illuminate\Support\Facades\Hash;use App\Mail\WelcomeMail;use Illuminate\Support\Facades\Mail;use DB;use Session;use Redirect;use Carbon\Carbon;use App\Libraries\GlobalHelpers;use App\Libraries\ImageHelpers;use Auth;use Response;class UserController extends Controller{ protected $userValidationRules = [ 'user_name' => 'required', 'email' => 'required|email|max:255|unique:users', ]; public function addUsers() { $validator = JsValidator::make($this->userValidationRules,[],[],'#addusers'); return view('user.add')->with(['validator' => $validator]); }}以下是视图文件中的代码@extends('user.layout.app')@section('content') <script src="{{ url('js/user/location.js') }}"></script> <div class="container-fluid add-location"> <div class="row"> <div class="col-md-12"> <div class="card"> <form method="post" action="{{ route('storeUsers') }}" name="addusers" id="addusers" enctype="multipart/form-data" novalidate> {{ csrf_field() }} <div class="card-header"> <h4 class="card-title"> Add Users </h4> </div> @if(!empty($errors->all())) <div class="row"> @foreach ($errors->all() as $error) <div class="col-lg-12"> <div class="alert alert-danger"> <span>{{ $error }}</span> </div> </div> @endforeach </div>有什么问题,为什么唯一验证不起作用?
2 回答
白衣非少年
TA贡献1155条经验 获得超0个赞
在提交存储时,您还需要通过验证规则,然后只有它会检查
$this->validate($request, [ 'email' => 'required|email|max:255|unique:users' ]);
温温酱
TA贡献1752条经验 获得超4个赞
protected $userValidationRules = [
'user_name' => 'required',
'email' => 'required|email|max:255|unique:users,email',
];
唯一:表格,列 https://laravel.com/docs/6.x/validation#rule-unique
- 2 回答
- 0 关注
- 99 浏览
添加回答
举报
0/150
提交
取消