我正在尝试从车辆页面传递URL变量,该变量将过滤为所选车辆创建的费用。页面呈现,但我收到一条消息,请参阅http://datatables.net/tn/1,我认为变量未到达控制器。请帮我解决。
谢谢。
index.blade
var vehicleexpensetable = $('#vehicleexpensetable').DataTable({
processing: true,
serverSide: true,
ajax: "{{action('\Modules\Essentials\Http\Controllers\VehicleExpenseController@index', request()->route('id'))}}",
columnDefs: [
{
targets: 2,
orderable: false,
searchable: false,
},
]
});
路线
Route::get('/vehicleexpenses/{id}','VehicleExpenseController@index');
VehicleExpenseController
public function index($id)
{
$BusinessID = request()->session()->get('user.business_id');
if (!auth()->user()->can('vehicle.view') && !auth()->user()->can('vehicle.create')) {
abort(403, 'Unauthorized action.');
}
if (request()->ajax()) {
$vehicleexpense = VehicleExpense::where('vehicle_expenses.BusinessID', $BusinessID)
->where('vehicle_expenses.VehicleID', $id)
->join('expense_types as et', 'et.id', '=', 'vehicle_expenses.expense_type_id')
->select([
'vehicle_expenses.id',
'et.ExpenseType',
'Expense',
'Amount',
'Location',
'CompletedDate',
'vehicle_expenses.BusinessID',
'Note'
]);
return Datatables::of($vehicleexpense)
->addColumn(
'action',
'@can("vehicle.update")
<button data-href="{{action(\'\Modules\Essentials\Http\Controllers\VehicleExpenseController@edit\', [$id])}}" class="btn btn-xs btn-primary btn-modal" data-container=".view_modal"><i class="glyphicon glyphicon-edit"></i> @lang("messages.edit")</button>
@endcan
@can("vehicle.delete")
<button data-href="{{action(\'\Modules\Essentials\Http\Controllers\VehicleExpenseController@destroy\', [$id])}}" class="btn btn-xs btn-danger delete_vehicleexpensebutton"><i class="glyphicon glyphicon-trash"></i> @lang("messages.delete")</button>
@endcan'
)
->editColumn('CompletedDate', function ($row) {
$CompletedDate = \Carbon::parse($row->CompletedDate);
$CompletedDate_formated = $this->moduleUtil->format_date($CompletedDate);
return $CompletedDate_formated;
})
->removeColumn('id','BusinessID')
->rawColumns([6])
->make(false);
}
$expensetypes = ExpenseType::forDropdown($BusinessID);
$vehicle = Vehicle::where('BusinessID', $BusinessID)
->find($id);
return view('essentials::vehicleexpense.index')->with(compact('expensetypes','vehicle'));
}