What is calling parseCookies? And what is $rawCookies?
Sep 19, 2024
3
Level 2
foreach() argument must be of type array|object, string given
Please help with the below error
ErrorException HTTP 500 Internal Server Error foreach() argument must be of type array|object, string given ErrorException Show exception properties ErrorException {#1531 ▼ #severity: E_WARNING
Route::get('gallery', [App\Http\Controllers\GalleryController::class, 'index'])->name('gallery');
//view
@foreach ($images as $
<div class="properties-img">
<a href="pro-details.html"><img src="assets/img/gallery/latest5.jpg" alt=""></a>
<img src="{{url('insta/images/')}}/{{$key.'.png'}}" alt=" " class="img-responsive">
</div>
@endforeach
//Controller
<?php
namespace App\Http\Controllers;
class GalleryController extends Controller
{
/**
* This function show the image from instagram.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$instagram = \InstagramScraper\Instagram::withCredentials(new \GuzzleHttp\Client(), 'username', 'Password#', new Psr16Adapter('Files'));
$instagram->login(); // will use cached session if you want to force login $instagram->login(true)
$instagram->saveSession(); //DO NOT forget this in order to save the session, otherwise have no sense
$account = $instagram->getAccount('username');
$accountMedias = $account->getMedias();
foreach ($accountMedias as $key => $accountMedia) {
$images[$key] = str_replace("&","&", $accountMedia->getimageHighResolutionUrl());
$path = $images[$key];
$imageName = $key.'.png';
$img = public_path('insta/images/') . $imageName;
file_put_contents($img, file_get_contents($path));
}
return view('gallery', compact('images'));
}
}
// From the line that the error says it is
private static function parseCookies($rawCookies)
{
$cookies = [];
foreach ($rawCookies as $c) {
$c = explode(';', $c)[0];
$parts = explode('=', $c);
$cookies[$parts[0]] = $parts[1];
}
return $cookies;
}
Please or to participate in this conversation.