我想在 中宣告值include,以便稍后我可以在檔案本身中呼叫它
首先我這樣做
@include('components.protected-email', ['key' => 'emails[0]'])
并在檔案本身
@php
$split = explode('@', $key);
$first = $split[0];
$second = $split[1];
@endphp
<a href="" data-first="{{ $first }}" data-second="{{ $second }}" class="js-combaine-email"></a>
但我得到了錯誤
ErrorException Undefined offset: 1 (View: D:\wamp64\www\test\resources\views\components\protected-email.blade.php)
uj5u.com熱心網友回復:
您正在使用字串作為$key引數。您的字串不包含@字符,因此$split = explode('@', $key);將導致$split[0]保留您的完整字串,因為它無法分解。$split[1]不存在所以你得到
“ ErrorException 未定義偏移量:1... ”
假設您已$emails[0]定義某處更改
@include('components.protected-email', ['key' => 'emails[0]'])
到
@include('components.protected-email', ['key' => $emails[0]])
您可能還想$split[1]在分配之前檢查是否存在
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/322937.html
標籤:php laravel-blade
下一篇:無法排除依賴gradle
