laravel-admin detail页面添加表格
要在Laravel-Admin的详情页面中添加表格,您可以使用table方法来创建一个新的表格并传递数据。例如,如果您想在用户详情页面中显示用户的订单信息,可以按照以下步骤操作:
- 在
User模型中定义一个orders方法,该方法返回用户的所有订单信息。例如:
public function orders()
{
return $this->hasMany(Order::class);
}
- 打开
UserController控制器,并在show方法中使用with方法加载用户的订单信息。例如:
public function show($id)
{
$user = User::with('orders')->findOrFail($id);
return Admin::content(function (Content $content) use ($user) {
$content->header('User Detail');
$content->description('View user detail');
$content->body(view('admin.users.show', compact('user')));
});
}
- 在
resources/views/admin/users/show.blade.php视图文件中,添加一个新的表格来显示用户的订单信息。例如:
<div class="box box-info">
<div class="box-header with-border">
<h3 class="box-title">Orders</h3>
</div>
<div class="box-body">
<table class="table table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Product Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total Price</th>
</tr>
</thead>
<tbody>
@foreach ($user->orders as $order)
<tr>
<td>{{ $order->id }}</td>
<td>{{ $order->product_name }}</td>
<td>{{ $order->price }}</td>
<td>{{ $order->quantity }}</td>
<td>{{ $order->total_price }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
这将在用户详情页面中添加一个名为“Orders”的新表格,其中包含用户的所有订单信息。您可以根据需要自定义表格的外观和布局
原文地址: https://www.cveoy.top/t/topic/ffd5 著作权归作者所有。请勿转载和采集!