我遇到了@include 的问题。用用户数据填充一个表,我想在每条记录上@include 一个小的删除表单。
问题是在第一行中,表单被包含在没有标签的情况下,在其他行中表单仍然正确包含
有什么想法吗?
查看代码:
<table class="table table-bordered table-hover table-head-fixed">
<thead>
<tr>
<th>User</th>
<th>Email</th>
<th> </th>
</tr>
</thead>
<tbody>
@forelse ($users as $user)
<tr>
<td>{{ $user->name }}</td>
<td>{{ $user->email }}</td>
<td>
<div class="d-flex flex-nowrap">
@can('user-index')
<a href="{{ route('users.show', $user) }}" class="btn btn-secondary mr-2" title="View">
<i class="fas fa-eye"></i>
</a>
@endcan
@can('user-edit')
<a href="{{ route('users.edit', $user) }}" class="btn btn-primary mr-2" title="Edit">
<i class="fas fa-edit"></i>
</a>
@endcan
<!-- -->
@include('users.partials.delete')
<!-- -->
</div>
</td>
</tr>
@empty
<tr>
<td colspan="2">No users in this role</td>
</tr>
@endforelse
</tbody>
</table>
表单代码:
@can('user-delete')
<form action="{{ route('users.destroy', $user) }}" method="POST" onsubmit="if (!confirm('Really delete user {{ $user->name }} <{{ $user->email }}> ?')) return false;">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-danger" title="Delete">
<i class="fas fa-trash-alt"></i>
</button>
</form>
@endcan
我使用了 spatie 权限。 我试过 view:clear 和 cache:clear。
更新
结果 HTML 是:
<table class="table table-bordered table-hover table-head-fixed">
<thead>
<tr>
<th>User</th>
<th>Email</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr>
<td>Enos Lueilwitz</td>
<td>dagmar26@example.org</td>
<td>
<div class="d-flex flex-nowrap">
<a href="http://dev.local/users/2" class="btn btn-secondary mr-2" title="View">
<i class="fas fa-eye"></i>
</a>
<a href="http://dev.local/users/2/edit" class="btn btn-primary mr-2" title="Edit">
<i class="fas fa-edit"></i>
</a>
<input type="hidden" name="_token" value="GNAt0zsQim0JovKMWphVgWYY0g1L6UQCAuzznThj">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-danger" title="Delete">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</td>
</tr>
<tr>
<td>Mr. Favian Rippin PhD</td>
<td>willms.gardner@example.net</td>
<td>
<div class="d-flex flex-nowrap">
<a href="http://dev.local/users/51" class="btn btn-secondary mr-2" title="View">
<i class="fas fa-eye"></i>
</a>
<a href="http://dev.local/users/51/edit" class="btn btn-primary mr-2" title="Edit">
<i class="fas fa-edit"></i>
</a>
<form action="http://dev.local/users/51" method="POST" onsubmit="if (!confirm('Really delete user Mr. Favian Rippin PhD <willms.gardner@example.net> ?')) return false;">
<input type="hidden" name="_token" value="GNAt0zsQim0JovKMWphVgWYY0g1L6UQCAuzznThj">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="btn btn-danger" title="Delete">
<i class="fas fa-trash-alt"></i>
</button>
</form>
</div>
</td>
</tr>
</tbody>
</table>
您可能会看到表格的第一行中没有标签(搜索 fas fa-trash-alt)。
我试图将@can() 从部分中取出并放入主模板 - 没有任何改变。