How to use php variable in laravel blade?

How to use php variable in laravel blade?

    If you want to use a php variable in Laravel blade engine, you can do like this. Add this 

    @php($x=0)

    in your blade , where x is your variable. You can initialize as you want. You can use the variable on the blade, even use it as an increment or decrement.

    If you want to use $x in your blade in foreach use like below

    @foreach($var as $v)
    
      {{$x++}}
    
    @endforeach

    Of course you can also do 

    {{$x--}}

    You must not forget to use double curly braces.

    Courses


    Recommended posts


    Recent posts