Back to API Generator Support

Filter results

Post a reply

Hello. I want to generate an api for retrieve news. My plugin' model has title(string), text(string), is_active(int), publish_date(datetime)

On apigenerator I'm setting {"fillable":"title,text,publish_date"} I would like to retrive only active=1 and publish_date<=today, but I'm getting all data. Is there an way I could filter this result?

I made the plugin So If it is not possible to do it by api generator I could do it on my code but please tell me where do I have to change.

Thank you.


This is my code

// Read JSON api $json = file_get_contents('XXXXXXXXXX/api/v1/alerts'); //Decode JSON $data = json_decode($json, true);
//get JSON desc $timenow=date( "Y-m-d H:i:s"); foreach ($data['data'] as $d){ if (($d['active']==1) and ($d['active_to'] >$timenow) ) { echo '

'. $d['title'].'
'. $d['content'].'



Thank you for your help, but this code is not usefull for my problem. I am able to code an foreach, I was asking where on my code I was suppose to put the code so the api generator could use on its query. If I put on plugin's code it could be overriden.

I was working on a update for this plugin to submit for the author on github so it could accept "scope" parameter and use a scope function on the model. But the deadline for my project was ending so I decided to uninstall this plugin and create my own api.

But anyway, thank you for take your time to answer.

1-3 of 3

Reply to this discussion

You cannot edit posts or make replies: You should be logged in before you can post.