Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blade compiler exception after upgrade to v5.8 #890

Closed
mnlm opened this issue Mar 8, 2019 · 8 comments
Closed

Blade compiler exception after upgrade to v5.8 #890

mnlm opened this issue Mar 8, 2019 · 8 comments

Comments

@mnlm
Copy link

mnlm commented Mar 8, 2019

  • Lumen Version: v5.8.1
  • PHP Version: 7.2.15

Description:

After upgrading from v5.7 to v5.8 I get the following error: ReflectionException: Class blade.compiler does not exist in ../vendor/illuminate/container/Container.php:794.

This is caused by calling the Blade::directive() function as shown below.

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {
        Blade::directive('test', function ($expression) {
            return "<?php echo 'test'; ?>";
        });
    }
}
@driesvints
Copy link
Member

The Blade facade doesn't comes out of the box with Lumen. You'll need to specifically set its alias in your bootstrap file:

$app->alias('blade.compiler', Illuminate\View\Compilers\BladeCompiler::class);

That should theoretically work.

@mnlm
Copy link
Author

mnlm commented Mar 8, 2019

Thanks for your reply. I set the alias as suggested but the error remains.

// bootstrap/app.php
$app->withFacades();
$app->alias('blade.compiler', Illuminate\View\Compilers\BladeCompiler::class);

Something must have changed since v5.7. The Blade facade worked fine then, just had to uncomment $app->withFacades(); in the bootstrap file.

@driesvints
Copy link
Member

This is the PR that changed the way it was resolved was this one: laravel/framework#25497

You did register the ViewServiceProvider manually didn't you? https://github.com/laravel/lumen/blob/38b12bccff7ba009bbc931ac0c5dc5e1d09a98a2/bootstrap/app.php#L82

@mnlm
Copy link
Author

mnlm commented Mar 8, 2019

You did register the ViewServiceProvider manually didn't you? https://github.com/laravel/lumen/blob/38b12bccff7ba009bbc931ac0c5dc5e1d09a98a2/bootstrap/app.php#L82

I didn't, but adding it doesn't change anything. Still the same error.

// bootstrap/app.php
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(Illuminate\View\ViewServiceProvider::class);

@driesvints
Copy link
Member

I can't really help you anymore at this point. Lumen doesn't work with views out of the box so I don't know for sure what's needed to make it work. I suggest you try one of the following support channels:

@driesvints
Copy link
Member

I meant Blade*

@mnlm
Copy link
Author

mnlm commented Mar 8, 2019

Ok, I will keep looking into it. Thanks for your time.

@Techworker
Copy link

I'm not using facades, but it might help you: I trigger the initialization of the 'view' instance in my AppServiceProvider::boot() method to make sure everything is bootstrapped.

Something like:

<?php

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        app('view');
        app('blade.compiler')->directive('my_directive', function ($expression) {
            return 'my_directive output';
         });
    }
   // ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants