Reputation: 1696
WHAT M GETTING IN MY VIEW.
THIS IS WHAT I DID.
providers = Yajra\Datatables\DatatablesServiceProvider::class,
aliases = 'Datatables' => Yajra\DataTables\Facades\DataTables::class,
my controller
use App\User;
use Datatables;
public function index(){
$users = User::select('first_name','last_name');
return Datatables::of($users)->make(true);
}
public function users(){
return view('user.users');
}
my routes
Route::get('/users', ['as' => 'user.users', 'uses' => 'UserController@users']);
Route::get('/index', ['as' => 'user.index', 'uses' => 'UserController@index']);
my view in users.blade.php
$(document).ready(function() {
$('#table1').DataTable({
processing: true,
serverSide: true,
ajax: "{{ url('index') }}",
columns:[
{ data: 'first_name', name: 'first_name' },
{ data: 'last_name', name: 'last_name' }
]
});
});
Upvotes: 1
Views: 3359
Reputation: 1696
I simply put defer in my dataTables.min.js script.
see here :
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js" defer></script>
Upvotes: 4
Reputation: 1366
Not sure if this is your issue or not but a potential problem. You have not gotten the data from the query builder.
Try something like this.
public function index(){
$users = User::select('first_name','last_name')->get();
return Datatables::of($users)->make(true);
}
Adding the ->get()
fetches the data.
Upvotes: 0