mercredi 29 août 2018

Searching for column name when its stored as an id

I have a table, where users can search data. They enter a search term and if it matches any of the table data results are returned.

This is the controller.

  $query = request('search-term');

      if(!empty($query))
      {
        $user = OnlineCounsellingApplication::where('name', 'like', $query)
                                              ->orWhere('email', 'like', $query)
                                              ->orWhere('country_id', 'like', $query)
                                              ->paginate(25)
                                              ->setPath('');}

If a user search an email, that email record will show up.

My issue is if a user searchers a country, no results are returned as I have countries stored as an id, which relates to a name on another table. It is stored as country_id. The record is initially displayed like so

  @foreach($users as $row)
      <tr>
        <td>{!! $row->id !!}</td>
        <td>{!! $row->name ?: 'No Name Provided'!!}</td>
        <td>{!! $row->email !!}</td>
        <td>{!! $row->country['name'] ?: 'No Country Provided' !!}</td>
</tr>
@endforeach

How to I accept a string as input and search for it based on the id



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire