我已经在Angular JS 2中写了一个表单,它发布到Laravel后端API并在那里得到验证..一切正常但是如果一个字段留空,那么当用户发布表单时它仍然写入数据库为' undefined'
无论如何使用laravels规则将此字符串分类为空?我当前的规则文件如下所示:
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class ContactFormRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
public function rules()
{
return [
"name" => "required|between:5,60",
"email" => "required|between:5,60",
"website" => "required|between:5,60",
];
}
public function messages()
{
return [
'name.between' => 'The :attribute must be between :min - :max.',
'name.required' => 'The :attribute is required!',
'email.between' => 'The :attribute must be between :min - :max.',
'email.required' => 'The :attribute is required!',
'website.between' => 'The :attribute must be between :min - :max.',
'website.required' => 'The :attribute is required!',
];
}
}