Reputation: 79
i have $result variable which is to be checked if it exists in the $frnd variable
how am i able to do this in blade template
@if(!is_null($result))
<h4>Search Results ( {{ count($result) }} )</h4> <br>
@foreach($result as $results)
<form role="form" method="POST" enctype="multipart/form-data" action="/friendlist">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="friendid" value="{{$results->id}}">
<div class="form-group">
<div class="col-md-9">
<ul><img class="smpic" src="/images/{{ $results->picture }}">
{{ $results->name }}
</ul>
</div>
@if(Auth::user()->id != $results->id)
<div class="col-md-3">
<button class="btnz btn"> Add Friend </button>
</div>
@endif
</div>
<br><br>
</form>
@endforeach
@endif
i also include the $frnd variable in the compact() that is to be compared with the $results. what im trying to get is to put the "Add friend" button only to those not in the $frnd.
Upvotes: 1
Views: 2103
Reputation: 7447
A generic way to check if a blade variables exists.
@if (isset($frnd)){
<div class="col-md-3">
<button class="btnz btn"> Add Friend </button>
</div>
@endif
See the Displaying Data under Echoing Data If It Exists.
If you are looking to check equality.
@if (isset($frnd) && ($frnd->id == $result->id)){
<div class="col-md-3">
<button class="btnz btn"> Add Friend </button>
</div>
@endif
Upvotes: 3