2

I need to parse this dataset I already but I tried several ways but it doesnt work.

{"id":2,"area_id":"1","payment_term_id":"1","payment_type_id":"1","trade_channel_id":"1","salesman_id":1,"customer_name":"xxx","contact_number":"1231212","fax_number":"1231232","home_address":"asd","delivery_address":"dasd","email_address":"[email protected]","created_by":"4","updated_by":"4","is_active":"1","created_at":"2017-10-17 06:02:59","updated_at":"2017-10-17 06:13:22"}

I tried this one but This error says that

(1/1) ErrorException Trying to get property of non-object

$details = $request->get('details');
return $details->id;

I also tried this one

$details = $request->get('details');
return $details['id'];

(1/1) ErrorException Illegal string offset 'id'

I'm using laravel 5.4

0

3 Answers 3

1

Since the data comes from the request, it a JSON and not a collection or an object. So, you need to do something like this:

return json_decode($request->details)->id;
Sign up to request clarification or add additional context in comments.

Comments

1

To use as array like $details['id'] try this :

$details = json_decode($request->details, true);
echo $details['id'];

Comments

1

To retrieve the JSON payload in your controller, use:

$details = json_decode($request->details)->id);
dd($details);

instead of

$details = $request->get('details');
return $details['id'];

1 Comment

You'll get Trying to get property of non-object with this code. You need to decode it first and then get ID.

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.