0
0

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.

[エラー解決] $dataが未定義です (@foreach ( $data as $item ))

Last updated at Posted at 2022-05-03

p.78 繰り返しのディレクティブ(PHPフレームワーク Laravel入門)

@foreach ( $data as $item)

//index.blade.php

Hello/Index

Blade/index

@foreachディレクティブの例

    @foreach ( $data as $item )
  1. {{$item}} @endforeach

//まとめ

▶︎元々こちらのindexアクションメソッドに記述したが、うまく動作せず。
public function index(){
// $data = ['one', 'two' ,'three' ,'four' ,'five'];
// return view('hello.index', ['data'=>$data]);
}
▶︎こちらのpostアクションメソッドに記述したら、正常に動作した。
public function post(Request $request){
// return view('hello.index',['msg'=>$request->msg]);
$data = ['one', 'two' ,'three' ,'four' ,'five','six',];
return view('hello.index', ['data'=>$data]);

}

**
(まだ方法がわからず文字化け的になってしまっていますが)
左バーのMarkdownで本文を見る、で見ると、コピペしたものがそのまま見ることができました。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?