0

我正在使用 Laravel 5.8,我想在cart.blade.phpBlade 上设置一个会话变量,如下所示:

@php
    $conflicted = '';
@endphp

@if($conflicting  && ($prd[0]->prd_delivery == 'city_free_delivery' || $prd[0]->prd_delivery == 'country_free_delivery'))
    @php Session::put($conflicted , '0') @endphp
        <p style="color:red;">
           This product has free delivery but it can not be set because of service area conflict of other products 
        </p>
@endif

@if(!$conflicting  && ($prd[0]->prd_delivery == 'country_free_delivery'))
    @php Session::put($conflicted , '1') @endphp
        <p style="color:red;">
           Country Free Delivery
        </p>
@endif
    
@if(!$conflicting  && ($prd[0]->prd_delivery == 'city_free_delivery'))
    @php Session::put($conflicted , '2') @endphp
        <p style="color:red;">
            City Free Delivery
        </p>
@endif

现在checkout.blade.php,我需要检查$conflicted变量的会话值。

那么如何在 Blade 上检查会话值?

因为使用getandhas方法,我可以检查会话密钥名称。

4

1 回答 1

0

您可以使用session()助手:

@if (session('conflicted'))
    {{ session('conflicted') }}
@endif
于 2021-07-06T09:23:18.460 回答