ratiw / vuetable-2-tutorial

MIT License
258 stars 67 forks source link

How to use filter with laravel API #104

Open eduardoarandah opened 6 years ago

eduardoarandah commented 6 years ago

Notes for lesson 13: https://github.com/ratiw/vuetable-2-tutorial/wiki/lesson-13

If you are using this package in laravel for your API https://github.com/santigarcor/laravel-vuetable

You need an extra param called "searchable"

Example

  <div class="form-inline">
    <input type="text" class="form-control mb-2 mr-sm-2" v-model="searchText" placeholder="Search..." @keyup="search">        
  </div>

method:

search () {
  this.moreParams={
    searchable: [
      'user.name',            
      'user.lastname',            
    ],
    'filter': this.searchText
  }
  Vue.nextTick( () => this.$refs.vuetable.refresh())
},
VasquezSRE commented 5 years ago

Hello @eduardoarandah

I can solve the problem, I'm reviewing the same and I have not been able to find the solution to apply the filter correctly.

At this moment the request is sent to the server but it does not search.

VasquezSRE commented 5 years ago

What I did is the following:

Controller

public function getUsersForVueDataTable(Request $request)
    {
        $request->request->add(['searchable' =>[ 'name', 'email', 'created_at']]);
        $query = User::select([
            'id',
            'name',
            'email',
            'created_at',
        ]);

        return Vuetable::of($query)->make();

    }

I do not think it is the most optimal solution but it works correctly.

Because I tried to add the query-params, but this did not work for me:

Component VueJs

                queryParams: {
                    sort: 'sort',
                    page: 'page',
                    perPage: 'per_page',
                    searchable: [
                        'name',
                        'email',
                        'created_at',
                    ],
                },

Request Controller dd($request->all())

This is the request object when I use the query-params but it does not take the variable

array:4 [
  "sort" => null
  "page" => "1"
  "per_page" => "5"
  "filter" => "andres"
]