1

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.

7
  • can you show ajax code. Commented Sep 20, 2016 at 12:47
  • $request_data = $request->all(); $user_name = $request_data['username']; Commented Sep 20, 2016 at 12:55
  • the issue is not with ajax coz I log in laravel but it gives me empty string : Log::info($request['username']); gives this in laravel.log : [2016-09-20 12:50:06] local.INFO: nothing Commented Sep 20, 2016 at 12:57
  • How is $request defined in your code? Commented Sep 20, 2016 at 14:19
  • here is how I'm able to access single value - $request['data']['username'] but it is still weird , laravel docs don't mention this syntax at all Commented Sep 20, 2016 at 15:43

3 Answers 3

1

Try this

$request['username'];

Hope this will work.

Sign up to request clarification or add additional context in comments.

6 Comments

Try to print your request in log and check that you are getting values or not. Or if possible share your code.
Log::info($request['username']); gives this in laravel.log : ` [2016-09-20 12:50:06] local.INFO: ` - empty
It means you are not getting 'username' param with your request. First check that you are getting all parameters in your request. Just use Log::info($request) and check that which parameters you are getting in request
here is Log::info($request) result [2016-09-20 15:39:10] local.INFO: array ( 'data' => array ( 'username' => 'blabla', 'password' => 'blabla', '_token' => 'JChRU2chhtTlcmLA2aml9Q3q0AZPF8n7xx4UtKls', ), )
here is how I'm able to access single value - $request['data']['username'] but it is still weird , laravel docs don't mention this syntax at all
|
0

use this one

Input::get('username');

or

Request::get('username');

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.