Skip to content

Commit

Permalink
@return directive condition option (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored and royduin committed Oct 23, 2024
1 parent 58a0acd commit 9cd33ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ The `@return` blade directive simply stops any further processing of the current
@return
```

Or only when a condition is true:
```blade
@return($someConditionIsTrue)
```

### @slotdefault

When you've an optional slot this directive gives you a cleaner way of defining a fallback. Normally you do something like this:
Expand Down
4 changes: 2 additions & 2 deletions src/BladeDirectivesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function register()
return "<?php echo (fn(\$markdown, \$html_input = 'escape') => Str::markdown(\$markdown ?? '', ['html_input' => \$html_input]))($expression); ?>";
});

Blade::directive('return', function () {
return "<?php return; ?>";
Blade::directive('return', function ($expression) {
return "<?php if ((fn (\$return = true) => \$return)($expression)) {return;}; ?>";
});

Blade::directive('slots', function ($expression) {
Expand Down

0 comments on commit 9cd33ec

Please sign in to comment.