List user messages logged in using Laravel

Asked

Viewed 99 times

0

Good afternoon.

I have in my Controller the method below:

public function lista () {        
    $mensagens =  Auth::user()->mensagens()->get();
    $title= "Mensagens";
    return view('auth.mensagens.lista',compact('mensagens','title'));
}

It returns a list of messages from the logged-in user. It turns out that in my data modeling, each message has a Boolean status of 0 or 1. How do I only return messages with status 1 ?

It must be something silly, but today I could not see a solution to this.

Grateful

  • By using Laravel, I believe you should know what the return of Auth::user()->mensagens(), correct? If you don’t know, start by researching this.

  • Thanks for the help.

1 answer

2


You can add a where in your consultation.

public function lista () {        
    $mensagens =  Auth::user()->mensagens()->where('status', 1)->get();
    $title= "Mensagens";

    return view('auth.mensagens.lista', compact('mensagens', 'title'));
}
  • Gee... that’s what I was missing: Where('status', 1)->get();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.