Last active
September 14, 2017 10:08
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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