Sage 10 - Custom directive

I am trying to create a simple directive but failing. Here’s my code:

namespace App\Providers;

use Blade;
use Roots\Acorn\ServiceProvider;

class ThemeServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
        Blade::directive('hello', function ($expression) {
            return "<?php echo 'Hello ' . {$expression}; ?>";
        });
    }
}

The error log shows:

production.WARNING: Skipping provider [App\Providers\ThemeServiceProvider] because it encountered an error. {"package":"","provider":"App\\Providers\\ThemeServiceProvider","error":"Class 'Blade' not found"

I think I am close but not sure what I need to change. Any help would be appreciated.

Thanks

Change use Blade; to use Illuminate\Support\Facades\Blade;

Thanks that has fixed the error. However, When i use the directive in a view it oupts the the directive text, ie I see “@hello(‘test expression’)” not “test expression”

Is there a further step that I am missing?

This topic was automatically closed after 42 days. New replies are no longer allowed.