From 7dc54e137319ea961f6b9c77ea0ed0e5a4a175dd Mon Sep 17 00:00:00 2001 From: Alex Justesen Date: Tue, 24 Dec 2024 10:23:30 -0500 Subject: [PATCH] [Feature] Added custom "blank" and "filled" Blade directives (#1951) --- app/Providers/AppServiceProvider.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6097b4add..a944e97e2 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -6,6 +6,7 @@ use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Console\AboutCommand; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Facades\URL; use Illuminate\Support\ServiceProvider; @@ -37,6 +38,8 @@ public function register(): void */ public function boot(): void { + $this->defineCustomIfStatements(); + RateLimiter::for('api', function (Request $request) { return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); }); @@ -52,4 +55,26 @@ public function boot(): void 'Out of date' => $system->isOutOfDate() ? 'Yes' : 'No', ]); } + + /** + * Define custom if statements, these were added to make the blade templates more readable. + * + * Ref: https://github.com/laravel/framework/pull/51561 + */ + protected function defineCustomIfStatements(): void + { + /** + * Adds blank() custom if statement. + */ + Blade::if('blank', function (mixed $value) { + return blank($value); + }); + + /** + * Adds filled() custom if statement. + */ + Blade::if('filled', function (mixed $value) { + return filled($value); + }); + } }