Skip to content

Commit

Permalink
[Feature] Added custom "blank" and "filled" Blade directives (#1951)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjustesen authored Dec 24, 2024
1 parent 07b8c59 commit 7dc54e1
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
});
Expand All @@ -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);
});
}
}

0 comments on commit 7dc54e1

Please sign in to comment.