Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 2 years ago.
0

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

  • 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()
    {
        //
    }
}
  • 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

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

moschel26 moschel26 Joined 21 Dec 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.