2

I call an API in response show an array in an object like this i share screen shot below

enter image description here

I want to remove the filter keyword in an activities object and rest of the response is same how i could do this. Please help Thanks in advance.

Here is my code below:

public function index(FilterRequest $request)
{
    $data = $this->filter($request);
    $mapsData = $data->original;

    return response()->json(['activities'=> $mapsData], 200);
}
8
  • 1
    You should look at Eloquent resources, especially the examples with the toArray functions. laravel.com/docs/5.7/eloquent-resources Commented Jan 2, 2019 at 14:25
  • The only way I can think of it would be to create a variable and store what data you need in it, however creating/storing a variable takes up memory on a server and when you're talking efficient code do you really need to? If you are not going to use the filter array just don't use it. Why do you not want it there? Commented Jan 2, 2019 at 14:34
  • You can simply unset() filters. If $mapsData is an array(), you can simple do unset($mapsData["filters"]). But it's recommended to do it earlier in the chain. Commented Jan 2, 2019 at 14:39
  • because the app wants that response thats why i do not want the filter Commented Jan 2, 2019 at 14:41
  • In where ican use this unset ? @Angua Commented Jan 2, 2019 at 14:44

2 Answers 2

1

you can use except method in laravel collections

https://laravel.com/docs/5.7/collections#method-except

Sign up to request clarification or add additional context in comments.

6 Comments

something like this : $filtered = $mapsData ->except(['filter']); return $filtered->all();
that removes the whole filter array but i only want to remove the filter keyword and rest of the response is same
No, this removes only filter keyword
but this removes all the reponse only show this activities:[]
I probably can help you if you can put your exported json file here
|
1
public function index(FilterRequest $request)
{

    $data = $this->filter($request);
    $mapsData = $data->original;

    return response()->json(['activities'=> $mapsData['filter']], 200);
}

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.