1

I have an issue dynamically accessing an array in one of my views.

I begin by organizing the values I need easy access to into $entityClubStats like this:

$entityClubStats = [];
foreach($entity->clubs as $club) {
    $entityClubStats[$club->name] = [
        'days_to_pay' => $club->pivot->days_to_pay,
        // ...
    ];
}

Then I iterate the master list of clubs with the intent of filling in relevant values if they exist:

@foreach (Club::isIncludedInStats()->get() as $club)
<div>
    <label>Name</label>
    <input type="text" value="{{$club->name}}" readonly />
</div>
<div>
    <label>Days to Pay</label>
    <input type="text" name="club_days_to_pay" value="{{$entityClubStats[$club->name]['days_to_pay']}}" />
</div>
<!-- ... -->
@endforeach

The problem is that while I've tried using {{double_brackets}} and <?= standard_syntax ?>, this segment results in a white screen:

$entityClubStats[$club->name]['days_to_pay'];

However, it does work when I simply hardcode the $club->name:

$entityClubStats['AAA']['days_to_pay'];

Why?

1 Answer 1

1

Turns out it died when it didn't see the $club->name it was looking for in $entityClubStats. Doh!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.