从其他控制器重用laravel验证规则

时间:2017-08-12 13:24:32

标签: php laravel

问:如何从其他控制器重用Auth的 ResigsterController 验证规则,而无需获取整个 RegisterController 类?
以下是规则:

...

protected function validator(array $data)
{
    return Validator::make($data, [
        'fname' => 'required|string|max:255',
        'lname' => 'required|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
        'tos' => 'boolean|accepted',
    ]);
}
...

另一个控制器:
应用\ HTTP \控制器\ UserController.php

public function update(Request $request, User $user)
{
    //I need to validate $request with the rules from
    //ControllersAuth\RegisterController.php
}

1 个答案:

答案 0 :(得分:0)

要重复使用相同的验证规则,您可以使用 Form Request Validation