I'm using vinkla/instagram composer package in my Laravel to fetch Instagram posts in my app.
Since Instagram allows the package to call their API 200 times per hour I'm trying to save post links into database table. And this package fetches 20 latest posts and its attributes.
Here I'm trying to compare the link of posts fetched by vinkla/instagram composer package and already saved posts and insert only unique into to table.
Below is the code snippet:
$instagram = new Instagram('access-token');
$posts = $instagram->media(); //gets 20 latest insta posts of a user
$fromDBs = Insta::orderBy('id', 'desc')->take(20)->get(); //get last 20 rows from table
foreach( $posts as $post)
{
foreach( $fromDBs as $fromDB)
{
if($post->images->low_resolution->url != $fromDB->link)
{
$create = new Insta;
$create->link = $post->images->low_resolution->url;
$create->save();
}
}
}
With the above stated code the new links are inserted x10 times.
What would be the correct way to insert unique link once only.