Hello Dev,
Hope all are good.Today in this post i will focus on foreach loop laravel 8 blade example.From here you will learn how to foreach loop laravel blade?i will show you it step by step .Also i will explain laravel foreach in blade. So from here i will help you and also give a good example of laravel foreach loop example. Just follow bellow step for foreach laravel blade.
This is very simple example for foreach loop statement in laravel 5.*,laravel 6, laravel 7 and also laravel 8 application.
So let’s start and see bellow simple example:
Blade File Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
@foreach ($users as $user)
<li>ID: {{ $user['id'] }}, NAME: {{ $user['name'] }}</li>
@endforeach
</ul>
</body>
</html>
Read Also : How to Include Blade File with Data in Laravel?
Controller File Code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AjaxController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function index()
{
$users = [
[ 'id' => 1, 'name' => 'Hardik'],
[ 'id' => 2, 'name' => 'Vimal'],
[ 'id' => 3, 'name' => 'Harshad'],
];
return view('ajaxRequest', compact('users'));
}
}
Read Also : Laravel 6 CRUD Operation
Thanks for read this, I hope it will you. You can also follow us on Facebook.