I'm new at Laravel and trying to do an Instagram CURL in Laravel.
previously(before Laravel), I put a CURL in a root/PHP/curl.php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// Pull and parse data.
$result = fetchData("https://graph.instagram.com/me/media?fields=id,media_url,permalink&access_token=this1st0k3n");
$result = json_decode($result, true);
and using <?php include "php/curl.php";?> at the most top of the page.
but in Laravel otherwise, I tried using a different method,
I tried to put the fetch data in a controller,
or I put it in resource/views/php/curl.blade.php so I called it on the top of the page using @include,
or I just plainly script on the same page like this
{{
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// Pull and parse data.
$result = fetchData("https://graph.instagram.com/me/media?fields=id,media_url,permalink&access_token=this1st0k3n");
$result = json_decode($result, true);
$limit = 6;
}}
@foreach ($result['data'] as $post)
@for ($i = 0; $i < $limit; $i++)
<div class="col-sm-6 col-md-6 col-lg-4 events">
<div class="portfolio-item">
<div class="gallery-thumb">
<a href=" {{$post['permalink']}}"target="_blank">
<img src="{{$post['media_url']}}" class="img-responsive" alt=""></a>
</div>
</div>
</div>
@endfor
@endforeach
none of these are working, please help me.