0

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)

1

1 Answer 1

1

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

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.