1

I'm working with Laravel 5.8 and I want to set a session variable at cart.blade.php Blade, like this:

@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

Now on checkout.blade.php, I need to check the session value of $conflicted variable.

So how can I check session value at Blade ?

Because with get and has method, I can check the session key name.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 2
    Blade views are meant for displaying things not setting variables to use somewhere else. That should be done in the controller. – shaedrich Jul 06 '21 at 09:07
  • @shaedrich I need to do this at Blade –  Jul 06 '21 at 09:09
  • What's the problem, you encounter? – shaedrich Jul 06 '21 at 09:10
  • @shaedrich I want to get `$conflicted` value by sessions. So I can check if it's value is 1, 2 or 0 –  Jul 06 '21 at 09:12
  • You already mentioned, you can get them by `Session::get($key)`. What do you need us for? Alternatively, you can use `session($key)` or `session()->get($key)` respectively. – shaedrich Jul 06 '21 at 09:13

1 Answers1

1

You can use session() helper:

@if (session('conflicted'))
    {{ session('conflicted') }}
@endif
Rouhollah Mazarei
  • 3,969
  • 1
  • 14
  • 20