DEV Community

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

dima2306 profile image

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 }}">
        <h2>No posts found</h2>
Enter fullscreen mode Exit fullscreen mode
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