Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use filter with laravel API #104

Open
eduardoarandah opened this issue Aug 22, 2018 · 2 comments
Open

How to use filter with laravel API #104

eduardoarandah opened this issue Aug 22, 2018 · 2 comments

Comments

@eduardoarandah
Copy link

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
Copy link

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
Copy link

VasquezSRE commented Jul 4, 2019

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"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants