Skip to content

Instantly share code, notes, and snippets.

@CupOfTea696
Created June 11, 2015 11:22
Show Gist options
  • Select an option

  • Save CupOfTea696/bc9a911039b9c012f62c to your computer and use it in GitHub Desktop.

Select an option

Save CupOfTea696/bc9a911039b9c012f62c to your computer and use it in GitHub Desktop.
Laravel Blade @define directive
<?php namespace Stribe\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Blade::directive('define', function($expression) {
$expression = preg_replace('/\\(([^,]+),(?:\\s)+?([^\\)]+)\\)/', '[$1 => $2]', $expression);
return "<?php extract({$expression}, EXTR_OVERWRITE); ?>";
});
}
/**
* Register any application services.
*
* This service provider is a great spot to register your various container
* bindings with the application. As you can see, we are registering our
* "Registrar" implementation here. You can add your own bindings too!
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment