【发布时间】:2021-06-23 02:20:49
【问题描述】:
您好,我是 laravel 新手,遇到了这个问题。
在我的控制器中,我返回了一个带有数组的视图,它运行良好
$cards = array('type' => 'news', 'value' => 'some value here');
return View::make('home')->with('cards', $cards);
在我的 home.blade.php 里面我有这样的东西:
<html>
<head> ... </head>
<body>
@foreach($cards as $card)
@component('components.card')
@slot('imageSource')
{{ $card['imageSource'] }}
@endslot
@slot('heading')
{{ $card['heading'] }}
@endslot
@slot('no_of_likes')
{{ $card['no_of_likes'] }}
@endslot
@endcomponent
@endforeach
</body>
</html>
上面的工作也很好。
主要问题在于我的card.blade.php,它看起来像这样:
<div>
<div class="row">
<div class="col-md-6"><a href="{{$imageSource}}"><img src="{{$imageSource}}" alt="Error: MD000 (image not found)" class="img-fluid img-thumbnail"></a></div>
<div class="col-md-6">
<h3>{{$heading}} </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>{{$no_of_likes}} likes</strong></div>
</div>
<hr>
</div>
<hr class="my-3 border-top" /> <!-- create a horizontal divider that will divide each card -->
</div>
现在的问题是我想在卡片中再添加一个 div,但前提是卡片的类型不是新闻。 而且我不知道如何在组件内部使用 if 语句来检查 $cards['type']
的值【问题讨论】:
标签: php laravel laravel-5 laravel-blade