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

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!

图片转代码服务由CSDN问答提供 功能建议

我在尝试使用laravel验证表单上的字段时遇到了一个奇怪的问题。 根据文档,为此,我需要这样做:

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

但是目前我收到这条烦人的消息“无法访问空属性”。

我已经跟踪了这个表达式 $的错误 this-> $ request-> all(),因为似乎没有定义all()属性...奇怪的是,如果我这样做,例如 $ this-> request-> input('name')我将在我的控制器上正确获取name ='name'输入所发送的值。

为什么该属性 似乎是空的? 有没有什么我缺少正确创建我的验证?

谢谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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();
    
    打赏 评论

相关推荐 更多相似问题