tobia

Experience

960

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 4 Lessons Completed
  • 0 Favorites

6th July, 2016

tobia left a reply on Render Template From Blade Template In Database • 1 year ago

I know this is old, but other people might find the answer useful.

As you have figured out, you can use Blade::compileString() to compile a piece of Blade template, taken for example from a DB column. What are Blade templates compiled to? If you look into storage/framework/views/ in your project folder, you will see that they are compiled into PHP code.

In fact, this is what compileString does:

Blade::compileString('Hello, {{ $planet }}!') 
===
'Hello, <?php echo e($planet); ?>!'

How can you evaluate that piece of PHP code against a custom array of variables?

Taking a hint from Illuminate\View\Engines\PhpEngine, here is one possible implementation:

function render($__php, $__data)
{
    $obLevel = ob_get_level();
    ob_start();
    extract($__data, EXTR_SKIP);
    try {
        eval('?' . '>' . $__php);
    } catch (Exception $e) {
        while (ob_get_level() > $obLevel) ob_end_clean();
        throw $e;
    } catch (Throwable $e) {
        while (ob_get_level() > $obLevel) ob_end_clean();
        throw new FatalThrowableError($e);
    }
    return ob_get_clean();
}

And here is how you'd use it in a route or in a controller method:

$blade = 'Hello, {{ $planet }}!';
$php = Blade::compileString($blade);
return render($php, ['planet' => 'World']);

6th June, 2016

tobia started a new conversation Can A Section @yield Itself? (Decorator Pattern) • 1 year ago

I would like to use the Decorator pattern on blade views, like this:

Master layout: ... ... @yield('content')

Sub-layout: @extends('layouts.master') @section('content') @yield('content') @stop

View: @extends('layout.subLayout') @section('content') My Content @stop

But I'm not getting the markup added by the sub-layout. Can a section @yield itself, meaning using / decorating the content defined by the child view?

15th April, 2016

tobia left a reply on .gitignore What Should Be Ignored? • 1 year ago

On the other hand, if you gitignore the vendor folder, you won't be able to use Git for deployment (push to your server to update your website) because you will have to run composer on your server. Plus, if some repository suddenly goes away from the Internet or is modified or corrupted (it happens) then you won't be able to run your old project anymore.

tobia left a reply on Do You Add Your CSS Files In Public/css/* To Your .gitignore ? • 1 year ago

What about development vs. production then?

Should I require all developers to run gulp --production (and commit) before pushing changes?

Otherwise I'll deploy non-minified public/css and js files

2nd March, 2016

tobia left a reply on How To Change The .env Filename • 1 year ago

My point is that .gitignore is a configuration file for version control, that is only edited when you need to and then left alone.

OTOH the ENV file needs to be visible and prominent (I'm even thinking of making it all caps) because it's the central configuration file for a given deployment or working copy. Whenever something is not working, it's the first place you (or an admin) should look into. Making it a hidden file is just looking for trouble and for a lot of wasted time.

29th February, 2016

tobia left a reply on How To Change The .env Filename • 1 year ago

Not unless you hide all hidden files and folders by default:

"file_exclude_patterns": [".*"],
"folder_exclude_patterns": [".*"],

which is how hidden files and folders should stay, IMHO

tobia started a new conversation How To Change The .env Filename • 1 year ago

I would like to load the environment from a env file instead of .env The reason is that my team will use Linux and Mac OS X, where dotfiles are hidden by default, so it may (will) become bothersome to check the existence of a hidden file whenever something is not working, especially one that is ignored by version control (as the env should be.) I managed to do it like this. Is it the right way? bootstrap/app.php: $app->loadEnvironmentFrom('env');

22nd January, 2016

tobia started a new conversation Why Do All Generated Files Use Spaces For Indentation? • 1 year ago

I was under the impression that Laravel favoured tabs over spaces (which I agree on) but all generated files, by the installer, by migrations, and so on, use four spaces.

Is there a global preference somewhere?

I'm using 5.2.10

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.