0

I am creating my API for mobile app in Laravel. I am facing an issue where I have to pass two arrays as json but it shows error. Here is the code which I am using

public function showSearchPage($subCatId)
{

$allAdQuery=DB::select('select * from addata where 
fk_adData_subCatData_id=:subId order by adData_date desc, adData_time desc',
["subId"=>$subCatId]);


$allProductQuery=DB::select('select sellerProductData_title, sellerProductData_price,
fk_sellerProductData_subCatData_id,sellerProductData_id from
sellerproductdata where fk_sellerProductData_subCatData_id=:subId
order by sellerProductData_date desc',["subId"=>$subCatId]);

return \Response::json($allAdQuery,$allAdQuery);

}

and it shows me this error

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR) Argument 2 passed to Symfony\Component\HttpFoundation\JsonResponse::__construct() must be of the type integer, array given, called in

Any idea how can I pass two or multiple arrays? Thanks

2
  • \Response::json([$allAdQuery,$allAdQuery]);? Commented Apr 4, 2020 at 19:24
  • @u_mulder thanks it Worked . Why dont You post this as an answer so i can mark it :) Commented Apr 4, 2020 at 19:27

1 Answer 1

1

Create array from your data as:

return \Response::json([
    $allAdQuery,
    $allAdQuery
]);

// with explicit keys:
return \Response::json([
    'key1' => $allAdQuery,
    'key2' => $allAdQuery
]);
Sign up to request clarification or add additional context in comments.

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.