Level 51
Can you please share the log entry from storage/logs/laravel.log that is created when you get the 500 error.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm getting a 500 (Internal Server Error) when trying to load the page. Maybe other eyes might see what I did wrong...
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Listing;
use Datatables;
use Yajra\DataTables\EloquentDataTable;
class AjaxdataController extends Controller
{
function dataAdmin()
{
return view('ajaxdata');
}
function getData()
{
$listing = Listing::select('id', 'name');
//$listing = new EloquentDataTable($query);
return Datatables::of($listing)->make(true);
}
}
ajaxdata blade file
<!DOCTYPE html>
<html>
<head>
<title>Datatables Server Side Processing in Laravel</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<br />
<h3 align="center">Datatables Server Side Processing in Laravel</h3>
<br />
<table id="student_table" class="table table-bordered" style="width:100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
</table>
</div>
<script type="text/javascript">
$(document).ready(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#student_table').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ route('ajaxdata.getData') }}",
"columns":[
{ "data": "id" },
{ "data": "name" }
]
});
});
</script>
</body>
</html>
Route
Route::get('ajaxdata', 'AjaxdataController@dataAdmin')->name('ajaxdata');
Route::get('ajaxdata/getData', 'AjaxdataController@getData')->name('ajaxdata.getData');
Listing Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Listing extends Model
{
public function user()
{
return $this->belongsTo('App\User');
}
}
Please or to participate in this conversation.