php - Laravel Stuck with returning a json request -> Integer Array -> receiving Eloquent Models -


i tried answer json request, returning laravel-models on delivered id's in request.

this - json-request { "places": [1,2, 3, 4, 5] }

first transform array:

convert request array

$array = $request->places; 

output:

array:5 [   0 => 1   1 => 2   2 => 3   3 => 4   4 => 5 ] 

and how receive models (1,2 manually entered id's in example: get places

$posts = post::wherein('place_id',[1,2] )->get(); 

my problem, placeholder [1,2] allows list of integer. i'm not able transform array placeholder variable this.

$posts = post::wherein('place_id',[$request] )->get(); 

if put array string variable, lets say: $request = "1,2,3,4,5" then, receive models first value (number 1 in case).

is there way transform json-requests receive laravel models?

any appreciated, cheers sebastian

you should try this.

$posts = post::wherein('place_id', $request->request->get('places', []))->get(); 

when request body is.

{     "places": [1, 2, 3, 4, 5] } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -