Home > front end >  Value inside include
Value inside include

Time:10-18

I want to declare the value inside the include, so that later I can call it in the file itself

First I do this

@include('components.protected-email', ['key' => 'emails[0]'])

and in the file itself

@php

$split = explode('@', $key);
$first = $split[0];
$second = $split[1];

@endphp
<a href="" data-first="{{ $first }}" data-second="{{ $second }}" class="js-combaine-email"></a>

But I get the error

ErrorException Undefined offset: 1 (View: D:\wamp64\www\test\resources\views\components\protected-email.blade.php)

CodePudding user response:

You're using a string as your $key parameter. Your string doesn't contain a @ character, so $split = explode('@', $key); will result in $split[0] holding your complete string, since it cannot be exploded. $split[1] does not exist so you get

"ErrorException Undefined offset: 1..."

Assuming you have $emails[0] defined somewhere change

@include('components.protected-email', ['key' => 'emails[0]'])

to

@include('components.protected-email', ['key' => $emails[0]])

You also might want to check if $split[1] exists before assigning it

  • Related