vendredi 26 mars 2021

How to check value passed with a view inside a component in laravel

Hi I'm new to laravel and stuck in this problem.

In my controller I'm returning a view with an array, which is working well

$cards = array('type' => 'news', 'value' => 'some value here');

return View::make('home')->with('cards', $cards);

inside my home.blade.php I have something like this:

<html>
<head> ... </head>
<body>
@foreach($cards as $card)
    @component('components.card')
        @slot('imageSource')
            
        @endslot

        @slot('heading')
            
        @endslot

        @slot('no_of_likes')
            
        @endslot
    @endcomponent
@endforeach
</body>
</html>

The above is also working fine.

The main problem lies in my card.blade.php, it looks something like this:

<div>
    <div class="row">
        <div class="col-md-6"><a href=""><img src="" alt="Error: MD000 (image not found)" class="img-fluid img-thumbnail"></a></div>
        <div class="col-md-6">
            <h3> </h3>
            <div class="btn-group" role="group" aria-label="Basic example">
                <button type="button" class="btn"><i class="fa fa-thumbs-up text-secondarysecondary" style="font-size: 3em; color: #808080;"></i></button>
                <button type="button" class="btn"><i class="fa fa-thumbs-down text-secondary" style="font-size: 3em; color: #808080;"></i></button>
                <button type="button" class="btn"><i class="fa fa-comment text-secondary" style="font-size: 3em; color: #808080;"></i></button>
            </div>
            <div><strong> likes</strong></div>
            
        </div>
        <hr>
    </div>

    <hr class="my-3 border-top" /> <!-- create a horizontal divider that will divide each card -->
</div>

Now the problem is I want to add one more div in the card but only if the type of the card is not news. And I have no idea on how to use if statement inside the component which checks the value of $cards['type']



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire