dongtiran7769
2016-09-20 12:45
浏览 392
已采纳

laravel $ request-> input()不起作用

I'm trying to retrieve a single input from laravel request

$request->input('username')

But it returns undefined in ajax response, I tried:

$request->only('username')

as well as:

$request->username`

but none of them work, exept for:

$request->all()

which returns the right data object:

Object {
    username: "username",
    password: "password",
    _token: "uKi2r3G1XPiOLhi13da3NC67ssjc1qmeiGWFtQNM"
}

So I need to access single values.

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

我正在尝试从laravel请求中检索单个输入

 < 代码> $ request-&gt;输入('用户名')
   
 
 

但它在 ajax 响应中返回undefined,我试过:

  $ request-&gt; only('username')
   
 
 

以及: $ request-&gt; username`

但它们都不起作用,代表: < pre> $ request-&gt; all()

返回正确的数据对象:

 对象{
用户名:“用户名”,
密码:“密码”,
 _token:“uKi2r3G1XPiOLhi13da3NC67ssjc1qmeiGWFtQNM”
} 
   
 
 

所以我需要 访问单个值。

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

3条回答 默认 最新

  • doutu6658 2016-09-20 12:48
    已采纳

    Try this

    $request['username'];
    

    Hope this will work.

    已采纳该答案
    打赏 评论
  • dqjo4340 2016-09-20 13:56

    use this one

    Input::get('username');
    

    or

    Request::get('username');
    
    打赏 评论
  • doudi1750 2016-09-20 14:00

    You can retrieve your data like this make model and make its table

     $posts = Post::orderBy('created_at','desc')->get();
    

    the above code will output the value according to date in descending order. this is the best way

    打赏 评论

相关推荐 更多相似问题