Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ Quickly output for classical ```$errors->has('input_name')``` to determine if a
@endhaserror
```

### @returnifempty

`return` if the given variable is empty. Useful when you want to return 'nothing' if the required parameter of a view component not provided.

```blade
@returnifempty($var)

{{-- The following codes won't get executed if $var is empty --}}
```

## Testing

```bash
Expand Down
10 changes: 10 additions & 0 deletions src/directives.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,14 @@
return '<?php endif; ?>';
},

/*
|---------------------------------------------------------------------
| @returnifempty
|---------------------------------------------------------------------
*/

'returnifempty' => function ($expression) {
return "<?php if (empty($expression) || ($expression && !count($expression))) { return; } ?>";
},

];