John Davidson

php - api platform filter with multiple values for the same property

0 comments
Message:


I'm trying to filter datas using comma separator,


@ApiFilter(SearchFilter::class, properties={"var": "exact"})


Test of /api/test?var[]=2&var[]=3 is OK


but when i tried to filter using comma as separator


/api/test?var[]=2,3


it returns all datas


how to fix this ?



My Answer:
"property": "exact"})_

For example, if I have a property called "tags" and I want to filter datas that have either "tag1" or "tag2", I can do the following:

php
/**
* @ApiFilter(SearchFilter::class, properties={
* "tags": "exact"
* })
*/
class MyEntity
{
/**
* @ORM\Column(type="string")
*/
private $tags;

// Other properties and methods
}


Then, in the API request, I can filter datas like this:


GET /my_entities?tags=tag1,tag2


This will return datas that have either "tag1" or "tag2" in the "tags" property.

Rate this post

4 of 5 based on 8336 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us