moses's avatar
Level 2

How to set a variable in blade (laravel 5.3)?

I try like this :

...

    @if(is_null($key['p3']))
        {{--*/$p3 = $key['p3']/*--}}
    @else
        {{ 0 }}
    @endif
    @if(is_null($key['wabku']))
        {{--*/$wabku = $key['wabku']/*--}}
    @else
        {{ 0 }}
    @endif
    <td class="tg-rv4w" width="5%">
        {{ number_format($p3 - $wabku,0,',','.') }}
    </td>

...

But, It's not working.

Is there any people who can help me?

0 likes
5 replies
ejdelmonico's avatar

Are you sure you want to set a variable in the view? That kind of takes away from separation of the model and view.

AddWebContribution's avatar
Level 42

You are using laravel-4 template comment syntax to define/set variables which is may be not working with L5.x.

But you can try@php ($p3 = $key['p3'])

OR

@php
$p3 = $key['p3']
@endphp

Above both are same.

digopauletti's avatar

You can use that:

@php ($p3 = $key['p3'])
@php ($wabku = $key['wabku'])
kirubha's avatar

Use $p3 = @$key['p3'] .If $key['p3'] is empty then itassigns zero to $p3.Otherwise if not null its assigns value to $p3.

Please or to participate in this conversation.