The change involves the way we handle the `username` filter in our audit logs search.
## Problem
Previously, the `username` filter was applied directly to the query using the `whereRelation` method:
```php
->whereRelation('user', 'username', '=', $this->username)
```
This approach had the limitation that it would always apply the `username` filter, even if `$this->username` was empty or not set.
## Solution
The solution was to use`when` to conditionally apply the `username` filter only when `$this->username` is set and not empty:
```php
->when($this->username, fn ($query) => $query->whereRelation('user', 'username', '=', $this->username))
```
## Expected Result
With this change, the `username` filter in the audit logs search will only be applied when `$this->username` is set and not empty.
All changes were tested for performance regressions. None of the included changes were affected. However, the code that uses `whereIn('category_id', Category::select('id')->where('movie_meta', '=', 1)` saw a ~10% performance loss so should not be changed.