4
votes

I am running laravel 5+ and included a package in my composer. It installed fine.

The package is simple, it allows me to add small bits of pseudo code into a given view and it renders a preset thing.

In my AppServiceProvider register() I am running:

 Shortcode::add('date', function($atts, $content, $name){
        return date('Y-m-d');
    });

and yes I included: use Shortcode; in the top of the AppServiceProvider.

I also reviewed the actual code and the add method is in there just fine.

In my config/app.php I have included:

Gornymedia\Shortcodes\ShortcodesServiceProvider::class, in the providers array.

I also included:

'Shortcode' => Gornymedia\Shortcodes\Facades\Shortcode::class,

in the alias array.

Why would this not simply work?

I know this is not a perfect question for stack. Just been stuck for awhile.

thanks

-- Additional info:

If I remove the ::class in the config/app.php So that is looks like:

'Shortcode' => Gornymedia\Shortcodes\Facades\Shortcode,

Then the error that shows is a fatal error:

Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Users/tjsherrill/Sites/c2c/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:218 Stack trace: #0 /Users/tjsherrill/Sites/c2c/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(396): Illuminate\Support\Facades\Facade::__callStatic('replaceNamespac...', Array) #1 /Users/tjsherrill/Sites/c2c/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(373): Illuminate\Foundation\Exceptions\Handler->registerErrorViewPaths() #2 /Users/tjsherrill/Sites/c2c/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(288): Illuminate\Foundation\Exceptions\Handler->renderHttpException(Object(Symfony\Component\HttpKernel\Exception\HttpException)) #3 /Users/tjsherrill/Sites/c2c/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php(187): Illuminate\Foundation\Exceptions\Handler->prepareResponse(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpKernel\Exception\H in /Users/tjsherrill/Sites/c2c/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 218

I then tried putting the whole thing in quotes:

'Shortcode' => 'Gornymedia\Shortcodes\Facades\Shortcode',

And that gets me back the first error.

1
Any chance you import a wrong class? Can you check within the class if there is a static add function?nakov

1 Answers

1
votes

I guess this is the package you are using laravel-shortcodes

I also included: 'Shortcode' => Gornymedia\Shortcodes\Facades\Shortcode::class,

The docs say add 'Shortcode' => Gornymedia\Shortcodes\Facades\Shortcode in the alais array without the class, correct that and let me know if it still doesn't work, glad to help.