1

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 &nbsp;&nbsp; ( {{ 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    }}">&nbsp;&nbsp;&nbsp;
            {{ $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.

1
  • I do not understand your question. Is $frnd it's own variable, a property of $results or a property of $result? Is $frnd an array of ids? Commented Oct 19, 2015 at 17:27

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.