这是我的路线
Route::get('/view/{id}', [
'uses' => 'ClientController@view',
'as' => 'view'
]);
这是我的客户端控制器
public function view($id){
$client = Client::where('id',$id)->first();
return view('view',compact('client'));
}
这是我的数据表
@extends('layouts.datatables_master')
@section('content')
<table class="table table-bordered" id="clients-table">
<thead>
<tr>
<th>ID</th>
<th>Company Name</th>
<th>Name</th>
<th>Surname</th>
<th>ID Number</th>
<th>Created</th>
<th>Last Updated</th>
<th>Actions</th>
</tr>
</thead>
</table>
@stop
@push('scripts')
<script>
$(function() {
$('#clients-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('business.list') !!}',
columns: [
{ data: 'id', name: 'id' },
{ data: 'companyname', name: 'companyname' },
{ data: 'name', name: 'name' },
{ data: 'surname', name: 'surname' },
{ data: 'idnumber', name: 'idnumber' },
{ data: 'created_at', name: 'created_at' },
{ data: 'updated_at', name: 'updated_at' },
{ data: "actions",
"render": function(data, type, row) {
return '<a href="{{route('view',1)}}" class="btn btn-xs btn-info"><i class="fa fa-search" title="View"></i></a> <a href="#" class="btn btn-xs btn-primary"><i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="Edit"></i></a> <a href="#" class="btn btn-xs btn-danger"><i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="Delete"></i></a>'
;}
}
]
});
});
</script>
@endpush
问题
我的主要问题是为所有用户传递ID。如果您在我的DataTable上查看我的render
函数,我说return route(view,1)
它在哪里1.我想传递$id
但是它表示未定义的变量。请帮忙。
答案 0 :(得分:2)
您可以从控制器返回生成的路线链接,如:
return datatables(Client::query())
->addColumn('actions', function ($client) {
return [
'edit_link' => route('view', [$id => $client->id]),
];
})->toJson();
并在视图中呈现为
{
data: "actions",
render: function(data, type, row) {
return
'<a href="' + data.edit_link + '" class="btn btn-xs btn-info">' +
'<i class="fa fa-search" title="View"></i></a>' +
'<a href="#" class="btn btn-xs btn-primary">' +
'<i class="fa fa-pencil" data-toggle="tooltip" data-placement="top" title="Edit"></i>' +
'</a>' +
'<a href="#" class="btn btn-xs btn-danger">' +
'<i class="fa fa-trash" data-toggle="tooltip" data-placement="top" title="Delete"></i>' +
'</a>';
}
}
答案 1 :(得分:0)
试试这个
type = "contour"
答案 2 :(得分:0)
您将客户端变量传递给刀片
{{ route('view',$client->id); }}
答案 3 :(得分:0)
data的值应为'id',并使用url()代替route():
{ data: "id",
"render": function(data, type, row) {
return '<a href="{{ url("view") }}/"'+ data +'>View</a>';
}
}