Laravel get data from API code example
Example 1: laravel check if api request
if (Request::wantsJson()) {
// return JSON-formatted response
} else {
// return HTML response
}
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();
Example 3: laravel get data from request
dd($request->all());
//print an array of the input name and the input value