4
votes

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?

1
@Raghavendra N, I try like that. But it's not workingsamuel toh
1) Don't do this. Setup your variables in your controller, or a view composer. 2) If you absolutely must, just open a <?php tag and keep it as short/clean/simple as possible. Actually, scratch that. Just follow #1.jszobody

1 Answers

1
votes

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.

Further you go with create own service provider like 1 create BladeServiceProvider:

<?php 
//app/Providers/BladeServiceProvider.php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class BladeServiceProvider extends ServiceProvider
{
    public function boot()
    {
        /* @datetime($var) */
        \Blade::extend(function($view, $compiler)
        {
            $pattern = $compiler->createOpenMatcher('datetime');

            return preg_replace($pattern, '$1<?php echo $2->format(\'m/d/Y H:i\')); ?>', $view);
        });

        /* @eval($var++) */
        \Blade::extend(function($view)
        {
            return preg_replace('/\@eval\((.+)\)/', '<?php ${1}; ?>', $view);
        });
    }

    public function register()
    {
        //
    }
}

2 Register BladeServiceProvider:

<?php
//in config/app.php add
return [

    // ...

    'providers' => [

        // ...

        'App\Providers\BladeServiceProvider',

Clear complied artisan clear-compiled Assign value to variable @datetime($updated_at)

OR

@eval($var = 1)

Taken reference from: Laravel 5 alternative