dongmiao260399 2017-01-26 17:32
浏览 403
已采纳

Laravel $ request-> all()抛出'无法访问空属性'消息

I'm having a weird problem trying to validate the fields on a form with laravel. According to the documentation, in order to do so I need to do this:

Validator::make($this->$request->all(), $this->$validationRules)

But currently I'm getting this annoying message 'Cannot access empty property'.

I have tracked the error to this expression $this->$request->all(), as it seems that all() property is not defined... Weird thing cause if I do, for instance something like $this->request->input('name') I'll get the value sent by the input with name='name' correctly on my controller .

Why is that property seems to be empty? Is there anything I'm missing to create my validations properly?

Thanks!

  • 写回答

1条回答 默认 最新

  • douzhanlie9209 2017-01-26 17:33
    关注

    Use this:

    $this->request
    

    Instead of this:

    $this->$request
    

    Also, check if you're injecting Request object first:

    public function method(Request $request)
    {
        $this->request = $request;
    

    Or you could just use request() global helper:

    request()->all();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器