I have a array as in the example. With the code I wrote, I get an output like in Output1.
Question: I am requesting a service different from my own application. The answer is an array and it contains id information. There is permission () for authorization control. The permission function returns user privileges as true and false. But I couldn't write the correct syntax because I couldn't remember this function completely. When I use my own code, I can pull the users who have permission as in output1. But I want the pagination information to remain in the array. As in Output2. What method should I apply?
This array is an example. I just tried to explain my own problem.
My code=>(Laravel 5.8)
$response = ….get(url)………
$list = $response->getBody()[‘content’];
$collection = collect($list);
$filtered = $collection->filter(function ($item) [
return auth()->user->permission($item['id'])
]);
Return [‘content’ => $filtered];
Raw Response:
[
"paginate"=>
[
"page"=> 5,
"per_page"=> 20,
"page_count"=> 20,
"total_count"=> 521,
"Links"=> [
["self"=> "/products?page=5&per_page=20"],
["first"=> "/products?page=0&per_page=20"],
]
],
"content"=> [
[
"id"=> 1,
"name"=> "Widget #1",
],
[
"id"=> 2,
"name"=> "Widget #2",
],
[
"id"=> 3,
"name"=> "Widget #3",
]
]
]
Output1:
[
"content"=>
[
"id"=> 1,
"name"=> "Widget #1",
],
----------------------> Authorized users(id= 1, 3) here, but no pagination.
[
"id"=> 3,
"name"=> "Widget #3",
]
]
expected output:
[
"paginate"=>
[
"page"=> 5,
"per_page"=> 20,
"page_count"=> 20,
"total_count"=> 521,
"Links"=> [
["self"=> "/products?page=5&per_page=20"],
["first"=> "/products?page=0&per_page=20"],
]
],
"content"=> [
[
"id"=> 1,
"name"=> "Widget #1",
"uri"=> "/products/1"
],
[
"id"=> 3,
"name"=> "Widget #3",
"uri"=> "/products/3"
]
]
]