laravel blade dynamic class loop foreach 1

laravel blade dynamic class loop foreach

Here is what the above code is Doing:
1. We’re using the @foreach directive to loop through the $posts variable.
2. We’re using the $loop variable to check if the current iteration is less than 3.
3. If the current iteration is less than 3, we’re adding the col-span-3 class to the component.
4. If the current iteration is greater than or equal to 3, we’re adding the col-span-2 class to the component.

Now, let’s add the following code to the resources/views/posts/index.blade.php file:

@extends(‘layouts.app’)

@section(‘content’)

@foreach ($posts as $post)

@endforeach

@endsection

Similar Posts