Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

abarua's avatar

Show link based on query result

Hi, I want to show a link if there are results from query. I get an error when the table is empty. Thanks in advance!

The html:

...
<div class="notification">
            <header><h3>Notification</h3></header>
            @if(Auth::user()->friends()->where(['status', 'received'])->first())
                <a href="" class="">You have a new request!</a>
                @endif
        </div>
...

The error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' (SQL: select * from `friends` where `friends`.`user_id` = 2 and `friends`.`user_id` is not null and (`0` = status and `1` = received) limit 1) 

At the beginning the table is empty unless the user saves some information in the table. How can I solve this?

0 likes
2 replies
edoc's avatar
edoc
Best Answer
Level 24

your syntax is wrong i think

@if(Auth::user()->friends()->where(['status' => 'received'])->first())

or

@if(Auth::user()->friends()->where('status', 'received')->first())

Please or to participate in this conversation.