我正在尝试使用yajara-laravel-database
这是我的控制器
public function index(Request $request){
$posts = Datatables::eloquent(Posts::query())->make(true);
return View::make('dashboard.approval', compact('posts'));
}
这是我的观点
<table class="ui celled table">
<thead>
<tr><th>id</th>
<th>Title</th>
<th>Description</th>
</tr></thead>
<tbody>
@foreach($posts as $post)
<tr>
<td>lsdjflajsdlk</td>
<td>Hello</td>
<td>Hello</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
这是我的脚本标签
<script>
$(document).ready(function(){
$('.table').DataTable({
});
});
</script>
我正在获取数据表结构。但目前我只得到 3 行,但我有 7 行数据,我通过将 {{$posts}} 放在 html 视图中进行验证。
{{$posts}} 的 HTML 视图
HTTP/1.0 200 OK Cache-Control: no-cache, private Content-Type: application/json {"draw":0,"recordsTotal":7,"recordsFiltered":7,"data":[{"id":"1",".............],"queries":[{"query":"select count(*) as aggregate from (select '1' as `row_count` from `posts`) count_row_table","bindings":[],"time":70.87},{"query":"select * from `posts`","bindings":[],"time":2.22}],"input":[]}
我尝试输入 {{$post->id}} 并收到此错误
Undefined property: Symfony\Component\HttpFoundation\ResponseHeaderBag::$id
试过的代码{{$post}}
htmlspecialchars() expects parameter 1 to be string, array given
填充数据的过程是什么。wiki 网址不起作用