How to create two columns with @foreach?

Posted 3 months ago by irankhosravi

HomeController.php

public function index()
{
    $slideshows = Slideshow::latest()->get();
    $services = Service::latest()->get();
    $faqs = Faq::latest()->get();
    return view('Home.index', compact('slideshows', 'services', 'faqs'));
}

home.blade.php

        <div class="row">
            @foreach($services as $row)
                <div class="col-md-6" data-aos="fade-right" data-aos-duration="2000">
                    @foreach($row as $service)
                        <div class="media mb-5">
                            <img src="images/services/{{ $service->image }}" class="rounded-circle" />
                            <div class="media-body">
                                <h5 class="mt-0">{{ $service->title }}</h5>
                                <p>{!! str_limit($service->body, 50) !!}</p>
                                <a href="{{ $service->path() }}">More Details</a>
                            </div>
                        </div>
                    @endforeach
                </div>
            @endforeach
        </div>

Error is:

Trying to get property of non-object (View: C:\xampp....)

Can you fix it? I don't have any idea what happened.

Please sign in or create an account to participate in this conversation.