我是laravel的新手。我想从数据库中获取数据并将其放入数据表。这是我的html
<div class="tab-pane" id="th_days_client" >
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<i class="material-icons">flag</i>
{{ $title }}
</h4>
<span class="pull-right">
<i class="fa fa-fw fa-chevron-up clickable"></i>
<i class="fa fa-fw fa-times removepanel clickable"></i>
</span>
</div>
<div class="panel-body">
<div class="table-responsive">
<table id="th_days_client_data" class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
为此的jQuery是:
var th_days_client;
$(document).ready(function () {
th_days_client = $('#th_days_client_data').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"columns":[
{"data":"name"},
{"data":"email"},
{"data":"mobile"},
{"data":"actions"}
],
"ajax": "{{ url('client') }}" + ((typeof $('#th_days_client_data').attr('data-id') != "undefined") ? "/" + $('#id').val() + "/" + $('#th_days_client_data').attr('data-id') : "/th_days_client_data")
});
});
控制器的功能是:
public function th_days_client_data(Datatables $datatables)
{
$clientObj = new Client;
$client = $clientObj->get()
->map(function ($client) {
return [
'id' => $client->id,
'name' => $client->first_name.' '.$client->last_name,
'email' => $client->email,
'mobile' => $client->mobile
];
});
return $datatables->collection($client)
->addColumn('actions', '@if(Sentinel::inRole(\'admin\'))
<a href="{{ url(\'client/\' . $id . \'/edit\' ) }}" title="{{ trans(\'table.edit\') }}">
<i class="fa fa-fw fa-pencil text-warning "></i> </a>
@endif
<a href="{{ url(\'client/\' . $id . \'/show\' ) }}" title="{{ trans(\'table.details\') }}" >
<i class="fa fa-fw fa-eye text-primary"></i> </a>
@if(Sentinel::inRole(\'admin\'))
<a href="javascript:void(0)" onclick="deleteClient({{$id}})" title="{{ trans(\'table.delete\') }}">
<i class="fa fa-fw fa-trash text-danger"></i> </a>
@endif')
->removeColumn('id')
->rawColumns(['actions'])->make();
}
我的路线是
Route::group(['prefix' => 'client'], function () {
Route::get('data', 'Users\ClientsController@data');
Route::get('pending_client_data', 'Users\ClientsController@pending_client_data');
Route::get('th_days_client_data', 'Users\ClientsController@th_days_client_data');
Route::get('{client}/edit', 'Users\ClientsController@edit');
Route::post('{client}/update', 'Users\ClientsController@update');
Route::get('{client}/show', 'Users\ClientsController@show');
Route::get('{client}/delete', 'Users\ClientsController@delete');
});
运行此命令时,出现500内部错误。当我转到laravel.log文件时,错误是:
[2018-08-01 08:59:27] local.ERROR: Method [th_days_client_data] does not exist on [App\Http\Controllers\Users\ClientsController]. {"exception":"[object] (BadMethodCallException(code: 0): Method [th_days_client_data] does not exist on [App\\Http\\Controllers\\Users\\ClientsController]. at /var/www/webroot/ROOT/files/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:68)
我该如何解决?