这是我的汽车索引刀片代码:
@extends('layout.master')
@section('content')
<div id="content" class="content">
<h1 class="page-header">Car <small>panel</small></h1>
@include('partials.message')
<div class="row">
<div class="col-md-12">
<div class="panel panel-inverse" data-sortable-id="ui-general-1">
<div class="panel-heading">
<div class="panel-heading-btn">
<a href="{{ route('car.create') }}" class="btn btn-xs btn-success"><i class="fa fa-plus"></i> Add</a>
</div>
<h4 class="panel-title">Car</h4>
</div>
<div class="panel-body">
<table class="table table-bordered" id="datatable" style="width: 100%">
<thead>
<tr>
<th>Car Category</th>
<th>Year</th>
<th>Color</th>
<th>Plate No</th>
<th>Status</th>
<th>Action</th>
</tr>
<tr id="filterRow" class="hidden-xs">
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
<th class="text-center"></th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<a href="javascript:;" class="btn btn-icon btn-circle btn-success btn-scroll-to-top fade" data-click="scroll-top"><i class="fa fa-angle-up"></i></a>
</div>
@include('partials.modalDelete')
</div>
@endsection
@push('pageRelatedJs')
<script type="text/javascript">
$(document).ready(function(){
var datatable = $('#datatable').DataTable(
{
dom: "lfrtip",
responsive: true,
processing: true,
serverSide: true,
ajax: {
url: "{{ route('car.list') }}",
data: { '_token' : '{{csrf_token() }}'},
type: 'POST',
},
columns: [
{ data: 'car_category_id', name: 'car_category_id', className: 'text-center',},
{ data: 'year', name: 'year', className: 'text-center', },
{ data: 'color', name: 'color', className: 'text-center', },
{ data: 'plate_no', name: 'plate_no', className: 'text-center', },
{ data: 'status', name: 'status', className: 'text-center', },
{ data: 'action', name: 'action', className: 'text-center', orderable: false, searchable: false },
],
initComplete: function () {
this.api().columns().every(function () {
$('#datatable thead tr#filterRow th:not(:last-child)').each( function () {
var title = $('#datatable thead th').eq( $(this).index() ).text();
$(this).html( '<input type="text" class="col-md-12" placeholder="Search by '+title+'" />');
});
$("#datatable thead input").on('keyup change', function () {
datatable.column( $(this).parent().index()).search(this.value).draw();
});
});
}
});
});
</script>
<script src="{{ asset('assets/js/modal_delete.js') }}"></script>
@endpush
如何通过ID获取car_category [name]
。
注意:2张表car_category和car
例如: 我有两个类别,1.suv 2.sport。我想添加一辆新车,当我提交它时,它会显示id而不是名字。任何想法?