From fc942969263514071eea8235aec1d0fc0c77622f Mon Sep 17 00:00:00 2001 From: yaquawa Date: Wed, 22 Jul 2020 20:41:01 +0900 Subject: [PATCH] Added `@returnifempty` --- README.md | 10 ++++++++++ src/directives.php | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 56afacc..91001c6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/directives.php b/src/directives.php index 8396f83..bc25a8e 100644 --- a/src/directives.php +++ b/src/directives.php @@ -399,4 +399,14 @@ return ''; }, + /* + |--------------------------------------------------------------------- + | @returnifempty + |--------------------------------------------------------------------- + */ + + 'returnifempty' => function ($expression) { + return ""; + }, + ];