PUT and POSTS AS Cron commands PHP Laravel 5 -


i have put api calls methods in model class. basic commands create() read() search() store() etc.

for start made these in controller class , i'm trying move logic controller commands can run scripts daily cronjob. reason wont work commands. because cant use put post calls cronjobs? since seams read functions works fine puts , posts won't work.

and if cant use put , post in crons, there workaround this?

here example code

public function handle() {     $mymodel = new mymodel;     $thing = array(         "title" => "my title",         "user_id" => 12345,         "org_id" => 54321,     );      $returned_id = $mymodel->create($thing); }   public function create($thing) {     $api_token = "xxxx";     $url = "https://api.api-site.com/thing?api_token=" . $api_token;      $ch = curl_init();     curl_setopt($ch, curlopt_url, $url);     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_post, true);      curl_setopt($ch, curlopt_postfields, $thing);     $output = curl_exec($ch);     $info = curl_getinfo($ch);     curl_close($ch);      //array data sent api     $result = json_decode($output, 1);     // check if id came     if (!empty($result['data']['id'])) {     $deal_id = $result['data']['id'];     return $deal_id;     } else {     return false;     } } 

get put post delete head http calls, these methods determined framework routing reading http headers , calls redirected appropriate function same routing. when run cronjob using cli not http there no headers , default interpreted get. rest methods not ment , neither should used anywhere else except http api calls. depending on app loginc there few things can do:

  1. create propper controller cli manages methods access (better way).
  2. create script uses curl access app via http(s) required http method. (hacky way)
  3. rework app rest api functionality not need triggered cron should not tied in way. (correct way)

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -