ErrorException Trying to get property 'product_id' of non-object (View:
I have my product_id in a foreach loop. My deal relationship is null for some that's why i'm getting the error.
@if($i->deal->product_id != $i->id)
@endif
when i acknowledge the null values, the error disappears, but then the if statement does not work. e.g
@if($i->deal->product_id ?? ' ' != $i->id)
@endif
how can i get the if statement working even with the null values?
@if ( $i->deal && $i->deal->product_id != $id->id )
@endif
like so
Yes, but with this only the elseif form is displaying, the if form is not displaying
@if($i->deal && $i->deal->product_id != $i->id)
<form action="{{ route('produce.store') }}" style="margin-left : 20px;float:right;" method="post" data-toggle="tooltip" data-original-title="Add to Deals">
{{ csrf_field() }}
<input type="text" name="deal" value="{{$i->id}}" hidden>
<button type="submit" class="btn btn-success"> Add to Deals</button>
</form>
@elseif($i->deal && $i->deal->product_id == $i->id)
<form action="{{ route('produce.update', $i->deal->id) }}" style="margin-left : 20px;float:right;" method="post" data-toggle="tooltip" data-original-title="Add to Deals">
{{ csrf_field() }}
<input type="text" name="deal" value="" hidden>
<button type="submit" class="btn btn-danger"> Remove Deal</button>
</form>
@endif
@if($i->deal !== null)
@if($i->deal->product_id != $i->id)
// do something
@elseif($i->deal->product_id == $i->id)
// do something else
@endif
@endif
Thanks, i ran it this way.
@if($i->deal == null)
@elseif($i->deal !== null)
@endif
Please or to participate in this conversation.