Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel search records by id #294

Open
matthiasvanwoensel opened this issue Dec 3, 2021 · 3 comments
Open

Laravel search records by id #294

matthiasvanwoensel opened this issue Dec 3, 2021 · 3 comments

Comments

@matthiasvanwoensel
Copy link

matthiasvanwoensel commented Dec 3, 2021

Is there any good way to search records by id?

this is what i get:

`public function toSearchableArray()
{

    $array = $this->toArray();

   
    $array['ticket_number'] = strval($this->id);
     // some other code
  
    return $array;

}

`

At the moment a created an extra array element "ticket_number", but this doesn't work properly, please can someone help me?

@DevinCodes
Copy link
Contributor

Hi @matthiasvanwoensel ,

Could you explain a bit more what exactly isn't working properly?

The code you sent should add the ticket_number attribute to your records. Please keep in mind you need to add the ticket_number attribute to your searchableAttributes in order for Algolia to search into the values here.

Thank you in advance!

@matthiasvanwoensel
Copy link
Author

matthiasvanwoensel commented Dec 17, 2021

Hi @matthiasvanwoensel ,

Could you explain a bit more what exactly isn't working properly?

The code you sent should add the ticket_number attribute to your records. Please keep in mind you need to add the ticket_number attribute to your searchableAttributes in order for Algolia to search into the values here.

Thank you in advance!

I cant search in numbers, only in strings ...

I have a field ticket number and a field client_number, both are numbers, but if i for example wants to search a client number (1001 or something like that), i don't get records... while it in the table exists..

` public function searchClients($term)
{
$clients = Client::search($term);
return $clients->orderBy('client_number', 'desc')->paginate(25);

}

@DevinCodes
Copy link
Contributor

Are these attributes configured as searchableAttributes? Could you show us the settings of your index, please? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants