diff --git a/laravel/blade.php b/laravel/blade.php index e3111d09..c5d44c48 100644 --- a/laravel/blade.php +++ b/laravel/blade.php @@ -16,6 +16,8 @@ class Blade { 'structure_openings', 'structure_closings', 'else', + 'unless', + 'endunless', 'includes', 'render_each', 'render', @@ -254,6 +256,30 @@ protected static function compile_else($value) return preg_replace('/(\s*)@(else)(\s*)/', '$1$3', $value); } + /** + * Rewrites Blade "unless" statements into valid PHP. + * + * @param string $value + * @return string + */ + protected static function compile_unless($value) + { + $pattern = '/(\s*)@unless(\s*\(.*\))/'; + + return preg_replace($pattern, '$1', $value); + } + + /** + * Rewrites Blade "unless" endings into valid PHP. + * + * @param string $value + * @return string + */ + protected static function compile_endunless($value) + { + return str_replace('@endunless', '', $value); + } + /** * Rewrites Blade @include statements into valid PHP. * diff --git a/laravel/documentation/changes.md b/laravel/documentation/changes.md index f7817d5e..976d07fe 100644 --- a/laravel/documentation/changes.md +++ b/laravel/documentation/changes.md @@ -28,6 +28,7 @@ ## Laravel 3.2 - [Added `$hidden` static variable to the base Eloquent model](/docs/database/eloquent#to-array). - [Added `sync` method to has\_many\_and\_belongs\_to Eloquent relationship](/docs/database/eloquent#sync-method). - [Added `save` method to has\_many Eloquent relationship](/docs/database/eloquent#has-many-save). +- [Added `unless` structure to Blade template engine](/docs/views/templating#blade-unless). - Migrated to the Symfony HttpFoundation component for core request / response handling. - Fixed the passing of strings into the Input::except method. - Fixed replacement of optional parameters in URL::transpose method. diff --git a/laravel/documentation/views/templating.md b/laravel/documentation/views/templating.md index 95582c2b..9cba301c 100644 --- a/laravel/documentation/views/templating.md +++ b/laravel/documentation/views/templating.md @@ -105,6 +105,19 @@ #### The "for-else" control structure: There are not posts in the array! @endforelse + +#### The "unless" control structure: + + @unless(Auth::check()) + {{ HTML::link_to_route('login', 'Login'); }} + @endunless + + // Equivalent... + + + ... + + ## Blade Layouts