Title / Description
Code <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Validator; use Blade; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { /** * App validator rules */ Validator::resolver(function($translator, $data, $rules, $messages) { return new \App\Validators\ExistsValidator($translator, $data, $rules, $messages); }); } /** * Register any application services. * * @return void */ public function register() { /** * Register Blade Template Extensions. */ // Add @continue for Loops Blade::directive('continue', function($expression) { return '<?php continue; ?>'; }); // Add @break for Loops Blade::directive('break', function($expression) { return '<?php break; ?>'; }); // Add @dd for debugging Blade::directive('dd', function ($expression) { return "<?php dd({$expression}); ?>"; }); // Add @debug for debugging Blade::directive('debug', function ($expression) { return "<?php debug({$expression}); ?>"; }); // Set variable Blade::directive('set', function ($expression) { // Break the Expression into Pieces $segments = explode(',', $expression, 2); // Return the Conversion return "<?php " . $segments[0] . " = " . $segments[1] . "; ?>"; }); /** * ACL */ // has(module) : Blade::directive('module', function($expression) { return "<?php if (Auth::check() && Auth::user()->hasModule({$expression})): ?>"; }); Blade::directive('endmodule', function() { return "<?php endif; ?>"; }); // is(role) : Blade::directive('role', function($expression) { return "<?php if (Auth::check() && Auth::user()->isRole({$expression})): ?>"; }); Blade::directive('endrole', function() { return "<?php endif; ?>"; }); // can(permission) : Blade::directive('permission', function($expression) { return "<?php if (Auth::check() && Auth::user()->canPermission({$expression})): ?>"; }); Blade::directive('endpermission', function() { return "<?php endif; ?>"; }); // Switch case (blade) [Exemple dans sidebar/menu.blade.php] // http://stackoverflow.com/questions/29897508/switch-in-laravel-5-blade Blade::extend(function($value, $compiler) { $value = preg_replace('/(\s*)@switch\((.*)\)(?=\s)/', '$1<?php switch($2):', $value); $value = preg_replace('/(\s*)@endswitch(?=\s)/', '$1endswitch; ?>', $value); $value = preg_replace('/(\s*)@case\((.*)\)(?=\s)/', '$1case $2: ?>', $value); $value = preg_replace('/(?<=\s)@default(?=\s)/', 'default: ?>', $value); $value = preg_replace('/(?<=\s)@breakswitch(?=\s)/', '<?php break;', $value); return $value; }); } }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code