Trying to get property 'likes' of non-object (View: /app/resources/views/products/productView.blade.php)

丶灬走出姿态 提交于 2020-04-30 11:06:32

问题


on my local server this is working and on hosting (when I push it on heroku) it gives me an error. I dont know where I am doing this wrong

Trying to get property 'likes' of non-object (View: /app/resources/views/products/productView.blade.php)

Query

$findLikes = Comment::where('user_id', Auth::user()->id)->where('product_id', $id)->first();

View

@if((Auth::check()) && ($findLikes->likes == '1'))

    <a href="/unlike-product/{{$p->id}}" id="myNumber" name="likes" value="0" onclick="myFunction()"><i class="fa fa-heart-o"></i> UnLike</a> </small>

@elseif((Auth::check()) && ($findLikes->likes == '0'))

    <a href="/liked-product/{{$p->id}}" id="myNumber" name="likes" value="1" onclick="myFunction()"><i class="fa fa-heart-o"></i> Like it</a> </small>

@endif

THIS IS I WHAT TRIED NOW AND NOT RETURNING ANYTHING BUT LOADING THE PAGE

@if((Auth::check()) && $findLikes)
    @if($findLikes->likes == '1')
       <a href="/unlike-product/{{$p->id}}" id="myNumber" name="likes" value="0" onclick="myFunction()"><i class="fa fa-heart-o"></i> UnLike</a> </small>
    @else
       <a href="/liked-product/{{$p->id}}" id="myNumber" name="likes" value="1" onclick="myFunction()"><i class="fa fa-heart-o"></i> Like it</a> </small>
     @endif
@endif

UPDATED

来源:https://stackoverflow.com/questions/60956460/trying-to-get-property-likes-of-non-object-view-app-resources-views-product

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!