Support the ongoing development of Laravel.io →
Requests Views Blade

I am getting this Undefined offset error when attempting to access an element in a nested array within a Laravel view. Here is the code for the view file.

@extends('layouts.app')

@section('content')
<div class="container-fluid">
    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="header">
                    <h4 class="title">{{ $gamertag }}'s Gameclips</h4>
                    <p class="category">You are currently viewing all gameclips.</p>
                </div>
                <div class="content">
                    <div class="row">
                        @foreach($gameclips as $gameclip)
                        <div class="col-md-6">
                            <a href="{{ url('/dashboard/gameclips/' .$gamertag. '/' .$gameclip['gameClipId']) }}">
                                <img src="{{$gameclip['thumbnails']['0']['uri']}}">
                            </a>
                            <h5>{{ $gameclip['titleName'] }}</h5>
                            <h5><i>{{ $gameclip['likeCount'] }} Likes </i></h5><h5><i>{{ $gameclip['views'] }}</i></h5>
                        </div>
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection('content')

You can see the offending line is in the image source. I don't understand why this returns an Undefined offset error. After trying for hours to access the data in the array I created a similar page using pure PHP with no Laravel installation. It worked exactly as intended leading me to think it is an issue with Laravel. Here is the code of the PHP file separate from my Laravel installation.

<?php
	$gamertag = $_GET['gamertag'];
	$curl = curl_init();

	curl_setopt($curl, CURLOPT_URL, "https://xboxapi.com/v2/xuid/$gamertag");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		'X-AUTH: 7a06dd46657c1a8ce35b82dc48e444801cb9a76a'
		));
	curl_setopt($ch, CURLOPT_HEADER, 0);

	$xuid = curl_exec($curl);

	curl_setopt($curl, CURLOPT_URL, "https://xboxapi.com/v2/$xuid/game-clips");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($curl, CURLOPT_HTTPHEADER, array(
		'X-AUTH: 7a06dd46657c1a8ce35b82dc48e444801cb9a76a'
		));
	curl_setopt($ch, CURLOPT_HEADER, 0);

	$result = curl_exec($curl);

	$gameclips = json_decode($result, true);
?>

<html> 
<head>
	<title><?php echo($gamertag) ?></title>
</head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<body> 
<div class="container">
	<div class="row">
		<div class="col-md-12">
		<?php foreach($gameclips as $gameclip): ?>
		<div class="col-md-4">
			<a href="<?php echo($gameclip['gameClipUris']['0']['uri']); ?>">
			<img src="<?php echo($gameclip['thumbnails']['0']['uri']); ?>">
			</a>
			<h5><?php echo($gameclip['titleName']); ?></h5>
		    <h5><i><?php echo($gameclip['likeCount']); ?> Likes</i></h5>
		</div>
		<?php endforeach; ?>
	</div>
</div>
</div>
</body> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</html>

Also here is the data in $gameclips that is passed to the view: Gameclip Array

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.