# Search one column from a Vue field

> when() adds a like query only when the search box is not empty. Bind the word. Do not paste it into SQL.

- URL: https://laravel-vuejs.space/laravel-where-search-vue
- Author: Anass Ez-zouaine (https://laravel-vuejs.space/author/anass-ez-zouaine)
- Published: 2026-10-11
- Topics: Laravel, VueJs, Inertia

People searching “Laravel Vue search” interpolate the query string into SQL. The [CRUD guide](https://laravel-vuejs.space/laravel-inertia-vue-crud) already has the filter form. This page is the query.

> **TL;DR**
>
> -   when() adds a like query only when the search box is not empty.
> -   Bind the word.
> -   Do not paste it into SQL.
> -   Do not use `whereRaw` with the request pasted in.
>
> **Who it's for:** Laravel + Vue developers on Inertia
>
> **Applies to:** Laravel 13 · Inertia 3 · Vue 3

## The fix

```php
$search = $request->string('search')->trim()->toString();

$posts = Post::query()
    ->when($search !== '', function ($query) use ($search) {
        $query->where('title', 'like', '%'.$search.'%');
    })
    ->orderBy('id')
    ->paginate(12)
    ->withQueryString();
```

`where()` binds the value. The percent signs are wildcards around a bound string, not a second query language. `withQueryString()` keeps `?search=` on the [pagination](https://laravel-vuejs.space/laravel-vue-pagination) links.

The Vue field is named `search`. Empty string skips the clause, so the first visit is the full list.

## What to avoid

> **Gotcha**
>
> Do not use `whereRaw` with the request pasted in. Do not `LIKE` against every column “to be helpful” unless you indexed that search on purpose. A leading wildcard does not use a normal index. That is acceptable on a small table and a problem on a large one.

## FAQ

**Q: How do I search one column from a Vue field?**

when() adds a like query only when the search box is not empty. Bind the word. Do not paste it into SQL.

**Q: What goes wrong with Laravel Vue search?**

Many developers interpolate the query string into SQL. Do not use `whereRaw` with the request pasted in.
