Laravel 表單驗證

Vckin發表於2019-01-21
$this->validate(
    $request, [
        'remarks'    => 'required|regex:/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\- ]+$/u',
        'cid'            => 'required|exists:computer_rooms,id',
        'url'             => 'required|url|unique:myurl',
        'username' => 'required|email',
        'password' => 'required|min:6',
        'token'        => 'required|regex:/^[a-zA-Z0-9\-\.]+$/u',
        'qq_url'       => 'required|url|regex:/^http:\/\/[a-zA-Z0-9\-\.:\&\?\/\=]+$/u'
    ]
);
//引數效驗
$this->validate(
    $request, [
    'name' => ['nullable','regex:/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\-\._ ]+$/u'],
    'level' => ['nullable','regex:/^[0-9]+$/u'],
    'is_tb' => ['nullable','regex:/^[0-9]+$/u'],
    'start_at' => ['nullable','date'],
    'end_at' => ['nullable','date']
],[
    "regex"=>":attribute 格式錯誤",
    "date"=>":attribute 日期格式錯誤",
    ],[
        'name' => "名稱",
        'level' => "等級",
        'is_tb' => "程度",
        'start_at' => "開始時間",
        'end_at' => "結束時間"
    ]
);
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章