I have this code on my dashboard.index view
<table class="table table-striped" id="artists-table">
<thead>
<tr>
<th>id</th>
<th>Name</th>
<th>Created_at</th>
<th>Updated_at</th>
</tr>
</thead>
</table>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#artists-table').DataTable({
processing: true,
servedSide: true,
responsive: true,
ajax: '{{route('admin.data')}}',
columns: [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'}
]
});
});
and this is my dashboardController code
class dashboardController extends Controller
{
//
public function __construct(){
$this->middleware('auth');
}
public function getIndex(){
return view('admin.dashboard.index');
}
public function getArtists(){
return Datatables::of(artist::query())->make(true);
}
}
and i have also wrote these two routes, the problem is this is not displaying the data from datatables as ajax only table headings is displayed. Auth::routes();
Route::get('/admin', 'dashboardController@getIndex')->name('admin');
Route::get('/admin.data', 'dashboardController@getArtists')->name('admin.data');
this code when I inspect the console I see it displays $ referenceError.
in my admin.blade.php master page I loaded all jquery and assets of datatables. like this as I am using Bootstrap 3.
<script src="{{ asset('theme/js/jquery-3.1.1.min.js') }}"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="{{ asset('theme/js/bootstrap.min.js') }}"></script>
<script src="{{ asset('js/app.js') }}"></script>
<script src="{{asset('theme/js/select2.min.js')}}"></script>
at the footer of the master page.
$in your code so make sure to include the jquery before you use it.