dpict99695329 2019-04-29 17:43 采纳率: 100%
浏览 202
已采纳

在registerController验证中访问Request参数

i have 2 type of user with different fields/columns in db (not the users table , users table is the same for both they have different profiles )

so in my registerController.php i have this validation function

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

which only covers 1 type of user , i need to access to

$request->input('user_type');

in this function so i can run proper validation for each users

i've tried something that used to work in older laravel version

private $request ; 
public function __construct(Request $request)
{
    $this->middleware('guest');
    $this->request = $request ; 
}

but in the 5.5 version of laravel it doesn't work i get

Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttp\Psr7\Request
  • 写回答

1条回答 默认 最新

  • dow98764 2019-04-29 18:54
    关注

    This happens when Laravel cannot resolve a dependency to the your __construct method. In your case this is Request $request. As shown in your error it is trying to inject a dependency GuzzleHttp\Psr7\Request that cannot be resolved by laravel (do not have the answer to that).

    Probably a quick fix for you would be to import the correct dependency at the start of your file.

    <?php
    
    namespace ...;
    
    use Illuminate\Http\Request;
    use GuzzleHttp\Psr7\Request as GuzzleRequest;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗