3

I have something like this in the route:

Route::post('/iteminfo/{item_id}','itemcontroller@get_item_info');

And something like this in the controller

public function get_item_info($request)
{
$item_image = Item_Image->where("item_id",$request)->first();
$item_something = Item_Something->where("item_id",$request)->first();
$item_more = Item_More->where("item_id",$request)->first();

return Response::json($item_image);

}

I want to return the 3 things but with return Response::json() I can only return 1 statement (as far as I know). Is there any way to return all of them?

0

2 Answers 2

13

You can pass an array as the json response. So craft an array based on your data and use it.

return Response::json(array(
    'item_image' => $item_image,
    'item_something' => $item_something,
    'item_more' => $item_more,
));
Sign up to request clarification or add additional context in comments.

1 Comment

don't forget use Response; at the top
7

Since it requires an Array parameter so you can construct an array from the variables

 return response()->json(['item_image ' => $item_image, 'item_something' => $item_something, 'item_more' => $item_more  ]);

Or

return Response::json(['item_image ' => $item_image, 'item_something' => $item_something, 'item_more' => $item_more  ]);

1 Comment

You forget the "p" letter. Must be return Response::json

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.