Skip to content

Commit 7dc54e1

Browse files
authored
[Feature] Added custom "blank" and "filled" Blade directives (alexjustesen#1951)
1 parent 07b8c59 commit 7dc54e1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Cache\RateLimiting\Limit;
77
use Illuminate\Foundation\Console\AboutCommand;
88
use Illuminate\Http\Request;
9+
use Illuminate\Support\Facades\Blade;
910
use Illuminate\Support\Facades\RateLimiter;
1011
use Illuminate\Support\Facades\URL;
1112
use Illuminate\Support\ServiceProvider;
@@ -37,6 +38,8 @@ public function register(): void
3738
*/
3839
public function boot(): void
3940
{
41+
$this->defineCustomIfStatements();
42+
4043
RateLimiter::for('api', function (Request $request) {
4144
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
4245
});
@@ -52,4 +55,26 @@ public function boot(): void
5255
'Out of date' => $system->isOutOfDate() ? 'Yes' : 'No',
5356
]);
5457
}
58+
59+
/**
60+
* Define custom if statements, these were added to make the blade templates more readable.
61+
*
62+
* Ref: https://github.com/laravel/framework/pull/51561
63+
*/
64+
protected function defineCustomIfStatements(): void
65+
{
66+
/**
67+
* Adds blank() custom if statement.
68+
*/
69+
Blade::if('blank', function (mixed $value) {
70+
return blank($value);
71+
});
72+
73+
/**
74+
* Adds filled() custom if statement.
75+
*/
76+
Blade::if('filled', function (mixed $value) {
77+
return filled($value);
78+
});
79+
}
5580
}

0 commit comments

Comments
 (0)