fetch data from api in laravel code example

Example 1: laravel fetch post

fetch(url, {   
      	headers: {     
          "Content-Type": "application/json",     
          "Accept": "application/json, text-plain, */*",     
          "X-Requested-With": "XMLHttpRequest",     
          "X-CSRF-TOKEN": token    
        },   
  		method: 'post',
  		credentials: "same-origin",
  		body: JSON.stringify({     name: name,     number: number   })  })
  	.then((data) => {
      		form.reset();       
      		window.location.href = redirect;   
    })  
  	.catch(function(error) {      
      console.log(error);    
    });  
}

Example 2: how to save data from api to laravel

$res = $gallery->request('GET','https://www.instagram.com/explore/tags/MIZONEDanceBattle/?__a=1');
    $data = json_decode($res->getBody()->getContents(), true);

    $gallery = Gallery::firtsOrCreate([
            'shortcode',
            'thumbnail_src',
        ], $data]); // add $data here
    $gallery->save();

Tags:

Php Example