Use Accessor in Global Search

Hi, the documentation says that we can use an accessor to feed the global search (see https://filamentphp.com/docs/3.x/panels/resources/getting-started#record-titles). I just tried that by using name as $recordTitleAttribute and it queries the table and does not use the accessor. Is there something missing in the docs or is there a bug?
class CompanyResource extends Resource
{
protected static ?string $model = Company::class;

protected static ?string $recordTitleAttribute = 'name';
class CompanyResource extends Resource
{
protected static ?string $model = Company::class;

protected static ?string $recordTitleAttribute = 'name';
5 Replies
DrByte
DrByte12mo ago
What do you mean by "does not use the accessor"? What was the query it used? More importantly, what actually happened when you used the global search? What data did it return? Can you show a short video capture of the global search being used?
alexanderkroneis
alexanderkroneisOP12mo ago
It‘s throwing an exception that name cannot be found in the users table. We‘re storing first and last name and concenating them via a Laravel Accessor / Attribute. I can provide a video tomorrow. 👍
DrByte
DrByte12mo ago
Okay, that's helpful information. Why is it looking for "name" in the "users" table when the model specified is "Company"? Did you add "name" to another resource as well, as copy/paste, instead of making it match a field in the model? Or have you customized the global search results "display" to include data from the users table too, but added the wrong attribute to it? Code samples would be helpful.
awcodes
awcodes12mo ago
Search doesn’t work with accessors because they are computed data and do not exist on the database. You need to implement a virtual column on the table if you want it to be searchable that way. Search queries the db not the model.
alexanderkroneis
alexanderkroneisOP12mo ago
I thought so 😅 Thanks!
Want results from more Discord servers?
Add your server