vue.jsvuejs2laravel-8vue-data-tables

fill datatable with vueJS


i´m trayin to fill my data table with vueJS and all my data from DB. I´m usign this library:

https://jamesdordoy.github.io/laravel-vue-datatable

It´s ok if i use this in my controller:

User::all()
return response()->json($query);

and in my component:

<div class="">
            <data-table :data="data" :columns="columns" @on-table-props-changed="reloadTable"></data-table>
        </div>

this library contain method to sortBy, orderBy, search by name, etc... with this:

use JamesDordoy\LaravelVueDatatable\Http\Resources\DataTableCollectionResource;
public function index(Request $request)
    {   
        $length = $request->input('length');
        $sortBy = $request->input('column');
        $orderBy = $request->input('dir');
        $searchValue = $request->input('search');
        
        $query = User::eloquentQuery($sortBy, $orderBy, $searchValue);

        $data = $query->paginate($length);
        
        return new DataTableCollectionResource($data);
    }

but if i use this in my controller in laravel 8 returned me:

Call to undefined method App\Models\User::eloquentQuery()

i don´t know if this it means to use get(), all().

Also, if i´m not use this and i to do all search manually, for example:

if(isset($sortBy)){
  $query = User::all()->sortBy($sortBy);

  $data = $query->paginate($length);
}
return response()->json($query);

returned me that:

Method Illuminate\Database\Eloquent\Collection::paginate does not exist

if i removed paginate and return $query, return all my data en my web browser console in network tab, but my table it´s empty...

for back-end i´m using laravel-8

in my web browser console return this message:

Invalid prop: type check failed for prop "data". Expected Object, got Array 

if i change :data in my component for :items error in web browser console disappear

i don´t understand that i´m doing wrong for in one case i can fill my table and in other not...

Thanks for read and help me


Solution

  • i resolve my question with this:

    $query = \DB::table('users')->orderBy($sortBy, $order)->paginate(10);
    

    with model i can´t