how to show only published Modules in browser Field?

Hi everyone. I have a model called customer. I want to make this customer selectable via the browser field. That works so far. However, it always displays all customers, not just the published ones. After researching, I tried the following in /app/Repositories/CustomerRepository.php public function getBrowserItemsQuery($query) { return $query->where(“published”, 1); } But all of them are still displayed. The status of whether published or not is also set correctly in the database.
5 Replies
Justin
Justin4w ago
You could do something like this
protected function getBrowserItems(array $scopes = [])
{
$filters = json_decode($this->request->get('filter'), true) ?? [];

if (!isset($filters['status'])) {
$filters['status'] = 'published';
$this->request->merge(['filter' => json_encode($filters)]);
}
return parent::getBrowserItems($scopes);
}
protected function getBrowserItems(array $scopes = [])
{
$filters = json_decode($this->request->get('filter'), true) ?? [];

if (!isset($filters['status'])) {
$filters['status'] = 'published';
$this->request->merge(['filter' => json_encode($filters)]);
}
return parent::getBrowserItems($scopes);
}
in your CustomerController
damian_oo
damian_ooOP4w ago
Hi Justin, thank you very much! That worked. Hi @Justin , Is there a place in the documentation where this is covered? I couldn't find your solution anywhere. It would be great to know this for future problems.
Justin
Justin4w ago
Sadly not, I've just been looking through twill's code
damian_oo
damian_ooOP4w ago
It's a shame that the documentation isn't really helpful with these kinds of problems. Thank you again for your help.
Justin
Justin4w ago
I agree, hopefully things like this will be added in the future when development on this project continues. And no problem!

Did you find this page helpful?