我正在尝试以表单形式实现数据表。我有一个表格,下面需要显示数据库中存在的所有数据。我正在关注教程https://www.youtube.com/watch?v=zwz_cMvASCo
我无法为DataTable编写Route方法,我所遵循的教程只显示了DataTable,但是这里有一个显示DataTable的表格。请参阅附件。
// OrderedBookController controller class
use App\OrderedBook;
use Datatables;
public function index()
{
return view('pages.booksin');
}
function fetchData()
{
$ordered_books = OrderedBook::select('BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks');
return Datatables::of($ordered_books)->make(true); //return an instance of the class or interface you request
}
//OrderedBook model class
class OrderedBook extends Model
{
//
}
我不知道如何编写路由方法来显示数据。
我的web.php
班
Route::resource('/order','OrderedBookController');
我的视图页面在resources\views\pages\booksin.blade.php
内
查看页面示例代码
<table id="showBooksIn" class="table table-bordered">
<thead>
<tr>
<th>BOOK ID</th>
<th>BILLED DATE</th>
<th>BILLED NUMBER</th>
<th>QUANTITY</th>
<th>PRICE</th>
<th>REMARKS</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function(){
$('#showBooksIn').DataTable({
"processing":true,
"serverside":true,
"columns":[
{"data": "BookID"},
{"data": "BilledNum"},
{"data": "BilledDate"},
{"data": "Qunatity"},
{"data": "Price"},
{"data": "Remarks"},
]
});
});
</script>
答案 0 :(得分:0)
public function index()
{
return view('pages.booksin', $this->fetchData());
}
尝试一下。