DEV Community

Discussion on: How to add simple search to your Laravel blog/website?

Collapse
dima2306 profile image
Dimitri

Indeed, this article is helpful for simple searches. Let me simplify foreach in blade, you just cycle through with forelse instead of checking with condition:

@forelse($posts as $post)
    <div class="post-list">
        <p>{{ $post->title }}</p>
        <img src="{{ $post->image }}">
    </div>
@empty
    <div>
        <h2>No posts found</h2>
    </div>
@endforeach
Enter fullscreen mode Exit fullscreen mode
Collapse
bobbyiliev profile image
Bobby Iliev Author

Yes!! forelse is very handy. I actually go over it in this post here:

How to use Forelse loop in Laravel Blade