Header Ads

Header ADS

laravel background image dynamic

 //Before static image in style.css

.blogs .box-container .box{
    flex: 1 1 33rem;
    padding: 2rem;
    height: 35vh;
    background: url(../images/blog\ \(1\).jpg) no-repeat;
    background-position: center;
    background-size: cover;
    border-radius: .5rem 2rem .5rem 2rem;
    text-align: center;
    display: flex;
    align-items: end;
    justify-content:center;
    position: relative;
    overflow: hidden;
}



//After dynamic with Laravel

<div class="box-container">
            @php
            $posts = App\Models\Post::all();  
            @endphp

            @foreach ($posts as $item)
            @php
            $imageUrl = asset('uploads/posts/' . $item->features_img);
            @endphp
            <div class="box" style="background-image: url('{{ $imageUrl }}');">
                <div class="content">
                    <h2>{{$item->title}}</h2>
                    <a href="#" class="btn">get info</a>
                </div>
            </div>
            @endforeach  
        </div>

No comments

Theme images by fpm. Powered by Blogger.