如何在Laravel代码中包含HTML按钮

时间:2019-07-08 03:25:07

标签: php laravel

如果条件不成立,我想显示一个按钮。在下面的代码中,如果输出不正确,我需要显示“关注组”按钮。一切正常,但我不知道将按钮放入Laravel代码的语法。

{{ Auth::user()->grpusers()->where('group_id', $group->id)->first() == True ? 'You are following this group' :   <a href="{{ route('group.follow', ['id' =>$group->id])}}" class="btn btn-primary">Follow Group</a>     }} 

2 个答案:

答案 0 :(得分:1)

您可以简单地使用if else

<p> 
@if( Auth::user()->grpusers()->where('group_id', $group->id)->first() == True)
You are following this group
@else
<a href="{{ route('group.follow', ['id' =>$group->id])}}" class="btn btn-primary">Follow Group</a>
@endif
</p>  

答案 1 :(得分:0)

使用@if/@else刀片directives

@if (auth()->user()->grpusers()->where('group_id', $group->id)->first() === true) 
    echo 'You are following this group';
@else
    echo '<a href="{{ route('group.follow', ['id' => $group->id]) }}" class="btn btn-primary">Follow Group</a>';
@endif