Problem making a field search by date and id

Asked

Viewed 46 times

1

I made a field search however I am not able to search by date or id.

The database I use is Postgres, I’m using Laravel 5.2 framework

public function scopeSearchByKeyword($query, $keyword)
{
   if ($keyword!='') {

        $query->where(function ($query) use ($keyword) {
            $query->where("nome_problema", "LIKE", "%$keyword%")
                  ->orWhere("id", "LIKE", "%$keyword")
                  ->orWhere("data_criacao", "LIKE", "%$keyword");
        });
    }
    return $query;
}
  • $keyword what can come from content in this variable? explain in your question the possible values?

1 answer

0

The "Where" method appears to have been misspelled, so try:

public function scopeSearchByKeyword($query, $keyword)
{
   if ($keyword!='') {

        $query->where(function ($query) use ($keyword) {
            $query->where("nome_problema", "LIKE", "%" .$keyword. "%")
                  ->orWhere("id", "LIKE", "%" .$keyword. "%")
                  ->orWhere("data_criacao", "LIKE", "%" .$keyword. "%");
        });
    }
    return $query;
}

Browser other questions tagged

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