app->singleton(ShortcodeProcessor::class, function ($app) { return new ShortcodeProcessor(); }); } /** * Bootstrap any application services. */ public function boot() { Blade::directive('shortcode', function ($expression) { list($shortcodeName, $shortcodeAttributes) = explode(',', $expression, 2); return "render(); ?>"; }); Blade::directive('processshortcodes', function ($expression) { return "process($expression); ?>"; }); Blade::directive('customshortcode', function ($expression) { return "processShortcodes($expression); ?>"; }); Paginator::useBootstrap(); } public function processShortcodes($content) { return preg_replace_callback('/\[([\w_]+)([^\]]*)\]/', function ($matches) { $shortcodeName = $matches[1]; $shortcodeAttributes = str::of($matches[2])->trim()->replace("'", "\"")->__toString(); return "@shortcode('$shortcodeName', $shortcodeAttributes)"; }, $content); } }