Skip to content

Instantly share code, notes, and snippets.

@cipto-hd
Last active September 14, 2017 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipto-hd/91a4ca34ed0f5d1ce15c8a66ee36c284 to your computer and use it in GitHub Desktop.
Save cipto-hd/91a4ca34ed0f5d1ce15c8a66ee36c284 to your computer and use it in GitHub Desktop.
ServiceProvider that create custom Laravel Blade directive for relative include (from the calling blade tempale)
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class BladeExtendServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
\Blade::directive('rinclude', function ($expression) {
$expression = \Blade::stripParentheses($expression);
$expression = "'" . str_replace('/', '.', substr(dirname(\Blade::getPath()), strlen(\Config::get('view.paths')[0]) + 1)) . "." . substr($expression, 1);
return "<?php echo \$__env->make({$expression}, array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
});
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment