How to implement the most efficient database search method in Laravel's Inertia/Vue
P粉458725040
2023-08-15 18:05:26
<p>I want to search the customer list and change the component as is. </p>
<p>I am currently searching for a specific customer using this link /customer/$searchColumn/$searchTerm?page=4</p>
<p>This is what my controller returns</p>
<pre class="brush:php;toolbar:false;">return Inertia::render('Dashboard', [
'customers' => Customer::whereLike("nr", (string)$request)->paginate(10),
]);</pre>
<p>Renders a paginated table of all found items. </p>
<p>Vue is currently very simple:</p>
<pre class="brush:php;toolbar:false;">
<pre class="snippet-code-html lang-html prettyprint-override"><code><script setup>
import { usePage } from '@inertiajs/vue3'
import Pagination from '@/mycompany/Pagination.vue';
const page = usePage()
</script></code></pre>
<code>
</code></pre>
<p>On the front end, I render a table using:</p>
<pre class="brush:php;toolbar:false;">
<pre class="snippet-code-js lang-js prettyprint-override"><code>v-for="customer in $page.props.customers.data"</code></pre>
<code>
</code></pre>
<p>I want a search box at the top of the table that reloads the results as I type. </p>
<p>I don't know where to start. </p>
For this case, you can use regular ajax/fetch requests to complete.
Inertia still utilizes laravel for routing, so it's impossible to complete this kind of form request without some kind of request or redirect.
Even the creator of
inertia.js
supports using xhr/fetch requests with inertia.