laravel blade检查db中是否存在经过身份验证的用户

时间:2017-12-12 06:57:21

标签: if-statement laravel-5.4 laravel-blade

我正在处理用户请求模型。根据下面提到的代码,如果在数据库中存在经过身份验证的use id,他应该看到竖起大拇指(字体很棒),假设他不应该看到请求按钮(字体真棒)。我使用ajax和JQuery,一切正常,但我还没有得到如何使用if条件检查它。有人帮我Plz ..

<div class="col-sm-1 follows" style="padding:0px">
    @if($followCount->user_id != Auth::user()->id) 
        <h2 id="deligate" value="1">
            <i class="fa fa-user-plus" data-toggle="tooltip" title="follow" ></i>
        </h2>
    @else(!empty($followCount->user_id)) 
        <h2 id="unfollow">
            <i class="fa fa-thumbs-up" data-toggle="tooltip" title="unfollow" style="display:none;color: #ff9933" id="test"></i>
        </h2>
    @endif
</div>  

1 个答案:

答案 0 :(得分:0)

为此,您必须仅使用刀片文件中的以下代码

<div class="col-lg-2 col-md-3 col-sm-4 col-xs-12">
        <a href="@Url.Action("Video", "Service")">
            <div class="owl-carousel owl-theme">
                <div class="item">
                    <img src="@service.serviceThumbpath" alt="@service.serviceName" title="@service.serviceName" />
                </div>
                @foreach (var thumb in videoThumbpath)
                {
                    <div class="item">
                        <img src="@thumb" alt="@serviceName" title="@serviceName" />
                    </div>

                }
            </div>
            <h5> @service.serviceName</h5>
            <div class="details">
                @{
                    _serviceRate = float.Parse(service.serviceRate);
                }
                <p class="pull-left">@service.VideoCount </p>

            </div>
        </a>
    </div>

此检查用户是否经过身份验证的用户,您无需为此添加额外代码。

仅使用Auth :: user()检查并匹配数据库中的用户表。

谢谢你,希望这对你有用。