What contains the $result variable ? Can you show the complete code before $array = ... ?
Nov 11, 2022
6
Level 7
Convert JsonResponse with json_decode not working?
When I dd I get this

I am trying to figure out how to access the content so I can do a for loop in the blade.
I tried to make this into a collection using
$array = collect(json_decode($result,true));
But when I dd this, I end up getting
null // app\Http\Livewire\Guest\Home\DisplayGoogleSheetsProducts.php:24
#GoogleSheetsSerivces
<?php
namespace App\Http\Services;
use Google\Client;
use Google\Service\Sheets;
use Google\Service\Sheets\ValueRange;
class GoogleSheetsServices
{
public $client;
public $service;
public $documentId;
public $range;
public function __construct()
{
$this->client = $this->getClient();
$this->service = new Sheets($this->client);
$this->documentId = 'ssasdasdsd';
$this->range = 'A:Z';
}
public function getClient()
{
$client = new Client();
$client->setApplicationName('One Stop Repair Phones');
$client->setRedirectUri('http://template-1stoprepair.test/');
$client->setScopes(Sheets::SPREADSHEETS);
$client->setAuthConfig('googleSheetsCredentials.json');
$client->setAccessType('offline');
return $client;
}
public function readSheet()
{
$doc = $this->service->spreadsheets_values->get($this->documentId,$this->range);
return $doc;
}
}
// inside livewire component
public function mount(Request $request)
{
$data = (new GoogleSheetsServices ())->readSheet();
$result = response()->json($data);
$array = collect(json_decode($result,true));
}
Level 102
@Jakub003 Why are you making it into a json response if you want to use it in blade. Arent you returning a view ? If so, just send the $data to the view
Please or to participate in this conversation.