How to join php requests right in Laravel 9?

Have the next request for seaching films via filters:

    public function show(Request $request, Film $film): View
    {

        $tags = $request->tags;
        $films = Film::query()
            ->when($request->get('tags'), function ($builder, $tags) {
                $builder->whereHas('tags', fn ($query) => $query->whereIn('id', $tags), '=', count($tags));
            })
            ->when($request->filled(['genre', 'actors', 'year', 'age', 'director', 'time', 'country']), function ($builder) use ($request) {
            $builder->getFilmBySearch($request);
            })
            ->paginate(20)
            ->withQueryString();

        return view('films.tagresult', [
            'films' => $films
        ]);
    }

But have a problem with second "when". That is

->when($request->get('tags'), function ($builder, $tags) {
                $builder->whereHas('tags', fn ($query) => $query->whereIn('id', $tags), '=', count($tags));

work correctly and return all films according request tags.

And block:

when($request->filled(['genre', 'actors', 'year', 'age', 'director', 'time', 'country']), function ($builder) use ($request) {
            $builder->getFilmBySearch($request);

not working at all, after an attempt to activate it (for example, filtering by director Spielberg), all films are displayed on one page, no filtering occurs. In model "Film" function getFilmBySearch($request) is highlighted in gray, as if it is not visible from the controller.

I tested this function, it works. If you remove all of the above and leave only such a request in the body

$films = $film->getFilmBySearch($request)->paginate(20);

then it will filter by all of the above categories except tags. Therefore, I am looking for a way to combine both of these blocks

when($request->get('tags'), function ($builder, $tags) {
                $builder->whereHas('tags', fn ($query) => $query->whereIn('id', $tags), '=', count($tags));

AND

$films = $film->getFilmBySearch($request)->paginate(20);

return correct filter results

so that it filters both by tags and by other categories (actors, directors, year, country, etc.)

Answer

Solution:

Solved.

I just add in filters (which called by function getFilmBySearch($request)) new filter Tags and implemented therethe construction:

class Tags implements Filterable
{

    public static function apply(Builder $builder, $value)
    {

       return $builder->whereHas('tags', fn ($query) => $query->whereIn('id', $value), '=', count($value));
    }
}

and that's it. All to be good.

Source