Php 在表单上创建附加验证注册默认laravel
此用户(mstanggota)表: MSTBeaswas表:Php 在表单上创建附加验证注册默认laravel,php,laravel,laravel-5,frameworks,laravel-5.2,Php,Laravel,Laravel 5,Frameworks,Laravel 5.2,此用户(mstanggota)表: MSTBeaswas表: Schema::create('mstbeasiswas', function (Blueprint $table) { $table->increments('id'); $table->string('no_anggota',10)->unique(); $table->string('nm_anak',25);
Schema::create('mstbeasiswas', function (Blueprint $table) {
$table->increments('id');
$table->string('no_anggota',10)->unique();
$table->string('nm_anak',25);
$table->string('kt_lahir',25);
$table->date('ttl');
$table->String('nm_skl',50);
$table->String('st_pend',6);
$table->String('lbg_pend',6);
$table->String('prov_skl');
$table->String('jenkel',9);
$table->integer('k_umum');
$table->integer('k_khusus');
$table->integer('score')->nullable();
$table->boolean('status')->default(0);
$table->string('ket',250)->nullable();
$table->string('img1',50)->nullable();
$table->string('img2',50)->nullable();
$table->string('img3',50)->nullable();
$table->timestamps();
});
我想再做一次验证。如果表mstbeaswas上不存在no_anggota,则用户无法注册,有什么可以帮助我的吗(
注册表单视图->无论您选择哪种方式,Laravel都可以正常工作。传统请求和AJAX请求都可以接受 您可以在控制器中进行验证,也可以创建另一个类。在这种情况下,我更喜欢第二个类,以避免让控制器变得糟糕和不清楚 我想你已经读过了 1.使用artisan命令创建类 2.编辑验证规则(随您的更改) 3.为每个字段设置名称(使用您的语言更改) 4.错误时的响应 5.在进入控制器之前验证每个请求
传统请求和AJAX的区别在于,您可以返回带有错误的
重定向
或JSON
。在这种情况下,我们选择了JSON
而不是重定向。这样您就可以在前端处理错误。是的,您可以。请参阅Laravel文档thnks的验证章节,但我想(是的,Laravel在传统的请求和ajax中也能很好地工作。我已经回答了。检查一下。问题是否已经解决?
Schema::create('mstbeasiswas', function (Blueprint $table) {
$table->increments('id');
$table->string('no_anggota',10)->unique();
$table->string('nm_anak',25);
$table->string('kt_lahir',25);
$table->date('ttl');
$table->String('nm_skl',50);
$table->String('st_pend',6);
$table->String('lbg_pend',6);
$table->String('prov_skl');
$table->String('jenkel',9);
$table->integer('k_umum');
$table->integer('k_khusus');
$table->integer('score')->nullable();
$table->boolean('status')->default(0);
$table->string('ket',250)->nullable();
$table->string('img1',50)->nullable();
$table->string('img2',50)->nullable();
$table->string('img3',50)->nullable();
$table->timestamps();
});
$ php artisan make:request UserRegisterRequest
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|max:10',
'nickname' => 'required|max:20',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6',
'permission' => 'required|numeric',
];
}
public function attributes ()
{
return [
'name' => '姓名',
'nickname' => '綽號',
'email' => 'E-Mail',
'password' => '密碼',
'permission' => '權限',
];
}
public function response(array $errors) {
return response()->json([
'status' => false,
'errors' => $errors
]);
}
public function account_add(UserRegisterRequest $request) {
// pass the validation
}