1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Laravel6] Blade構文を素のPHPと比較して理解する

Last updated at Posted at 2022-05-27

変数の出力

⚫ php

<?php echo $test; ?> または <?= $test; ?>

⚫ blade.php

{{ $test }}

/*
{{ }}で囲む事で出力出来ます。
これによりXSSの対策も同時に行ってくれます
*/

foreach の場合

※$array = [ ‘ hello ‘ , ‘ world ‘ , ‘ hoge ‘] のような配列が定義されているものとします。

⚫ php

<?php foreach ( $array as $value) : ?>
echo $value;
<?php endforeach; ?>

⚫ blade.php

@foreach ( $array as $value )
{{ $value }}
@endforeach
  • 条件の書き方だけ一緒

if 文

⚫ php

<?php if ( $array[ 0 ] === ‘ hello ’ ) : ?>
echo ‘ OK ’ ;
<?php else : ?>
echo ‘ NO ’ ;
<?php endif ; ?>

⚫ blade.php

@ if ( $array === ‘ hello ’ )
{{ ‘OK’ }}
@else
{{ ‘NO’ }}
@endif
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?