Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Inertia::reload or this.$inertia.get to filter datas ?

Hello,

I discover InertiaJS and I have read the documentation about partial reload and HTTP queries.*

I can click on checkboxes to filter the datas and I want to retrieve the filtered data from the database via a GET route.

I thought that Inertia.reload was appropriated, but I have difficulty to send some filter. I can also refill the students props with this.$inertia.get() but then I think that it reloads the entire page.

What's the best way to do what I need ? Do you have an example ?

Thanks a lot ;).

Vincent

0 likes
5 replies
Sinnbeck's avatar

Pretty sure they are more or less the same except you define the url with get(). Maybe show what you have and which part isn't working?

1 like
vincent15000's avatar

@Sinnbeck Well ... The params are not passed in the request's params.

watch: {
  filters(newValue, oldValue) {
    Inertia.reload({ filters: this.filters })
  }
},

When I write a console.log(filters), it works fine.

// Initial route loaded
http://localhost:8000/students

And the controller

public function index(Request $request)
{
    $filters = isset($request->filters) ? $request->filters : [];
    dd($filters);
    $only = isset($request->only) ? $request->only : null;
    $list = Student::
        with('path')
        ->with('project')
        ->withCount('sessions')
        ->orderBy('firstname')
        ->orderBy('lastname')
        // ->whereIn('active', $filters)
        // ->when($only, function($query) use ($only) {
        //     $query->whereIn('id', $only);
        // })
        ->get();
    $students = json_decode(StudentResource::collection($list)->toJson());
    // $students = StudentResource::collection($list)->toArray();
    // dd($list);
    return Inertia::render('Students/Index', compact('students'));
}

This worked fine without InertiaJS.

The dd($request->filters) shows an empty array, whereas it should contain [1] for example.

vincent15000's avatar

@Sinnbeck With Inertia.reload, even if I add some parameters, I don't get any parameter in the back. But with this.$inertia.get I get the additional parameters, but the page refreshes entirely.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@vincent15000 try nesting it in data:

Inertia.reload({ data: { filters: this.filters} })
2 likes

Please or to participate in this conversation.