LoginSignup
0
2

More than 1 year has passed since last update.

Laravel blade ディレクティブを追加する拡張機能を作った

Posted at

Add-Directives-To-Laravel-Blade

下記の記事を書いたついでに、暇なので作りました。

is_bool, is_array, is_int やら何やらも追加しようと思いましたが、テンプレート内ではほとんど使われないだろうなぁ…と思い除外しました。

用意されていたらある程度使われそう(※個人の感想です)なのに、標準で用意されていないものに絞って追加してます。

インストール方法

composer require kanagama/add-directives-to-larave-blade

追加されるディレクティブ一覧

@true

$conditions 条件式が true の場合のみ表示されます。

@true ($condition)
  // $condition が true の場合の処理
@endtrue

@false

$conditions 条件式が false の場合のみ表示されます。

@false ($condition)
  // $condition が false の場合の処理
@endfalse

@notempty

@empty ディレクティブと反対の挙動をします

$conditions が empty でない場合に表示されます

@notempty ($condition)
  // $condition が empty でない場合の処理
@endnotempty

@notisset

@isset ディレクティブと反対の挙動をします

$conditions が定義されていない、または null の場合に表示されます

@notisset ($condition)
  // $condition が定義されていない、または null の場合の処理
@endnotisset

@isnull

$conditions が null の場合に表示されます

@isnull ($condition)
  // $condition が null の場合の処理
@endisnull

@isnotnull

$conditions が null でない場合に表示されます

@isnotnull ($condition)
  // $condition が null でない場合の処理
@endisnotnull

@loop

$conditions の回数分表示されます

@foreach ディレクティブと同じく、$loop 変数が利用できます。

@loop ($condition)
  // $condition が 3 の場合、3回表示されます
  {{ $loop->index }}
@endloop

github

packagist

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2