How you can use the foreach function correctly with Laravel

Hi guys! Today I want to explain to you how you can use the foreach function correctly with Laravel 4.2. Also, I will explain to you how you can extract and display the data from your database.

I have created a simple table called data in my database with two columns id and info.

To extract data from my table, I will use this code:

$data = Data::all(); // this code will extract all information from my table
return View::make('page')->with(array('data'=>$data));

Next, I will use the foreach function to display the data:

@foreach($data as $info)
{{$info->info}}

@endforeach;

In the video below, you can see the results:









Leave a Comment