覆盖背包验证角色

时间:2018-01-14 10:14:05

标签: php laravel laravel-5.3 backpack-for-laravel

我做了什么:

我正在尝试覆盖背包表单验证角色(更新请求)。

UserUpdateCrudRequest.php

use App\Http\Requests\Backpack\PermissionManager\UserUpdateCrudRequest as UpdateRequest;

class UserUpdateCrudRequest extends \Backpack\PermissionManager\app\Http\Requests\UserUpdateCrudRequest 
{

    function __construct()
    {
        parent::__construct();
    }

    public function authorize()
    {
        // only allow updates if the user is logged in
        return \Auth::check();
    }

    public function rules()
    {
        $rules = [
            'name'     => 'required',
            'password' => 'confirmed',
        ];

        return $rules;
    }
} 

应用/ HTTP /控制器/管理/背包/ PermissionManager / UserCrudController.php

 public function update(UpdateRequest $request)
    {
        //code
    }

我期望发生的事情:

电子邮件字段在创建时是必填字段,在更新时不是必需的。

发生了什么:

ErrorException in UserCrudController.php line 18:
Declaration of App\Http\Controllers\Admin\Backpack\PermissionManager\UserCrudController::update() should be compatible with Backpack\PermissionManager\app\Http\Controllers\UserCrudController::update(Backpack\PermissionManager\app\Http\Requests\UserUpdateCrudRequest $request)

1 个答案:

答案 0 :(得分:-1)

如果我是对的, 你在UserCrudController内,

use Backpack\PermissionManager\app\Http\Requests\UserStoreCrudRequest as StoreRequest;

use Backpack\PermissionManager\app\Http\Requests\UserUpdateCrudRequest as UpdateRequest;

如果您想要在更新时强制要求电子邮件字段,则必须修改UserUpdateCrudRequest.php内的your-project/vendor/backpack/permissionmanager/src/app/Http/Requests并删除该行

'email'    => 'required',