search

Home  >  Q&A  >  body text

How to implement the most efficient database search method in Laravel's Inertia/Vue

<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>
P粉458725040P粉458725040529 days ago559

reply all(1)I'll reply

  • P粉903969231

    P粉9039692312023-08-16 00:01:21

    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.

    reply
    0
  • Cancelreply