【发布时间】:2022-07-26 21:53:50
【问题描述】:
我现在正在经历这个错误,以前没有发生过,我一直在尝试排除故障,但没有解决。 以下是错误行代码。
Actions</th>
</tr>
</thead>
<tbody>
@php
$count = 1;
@endphp
@foreach ($accounts as $account)
<tr role="row" class="odd">
<td class="sorting_1">{{ $count++ }}</td>
<td>{{ date('F d, Y', strtotime($account->created_at))
}}</td>
<td><label data-toggle="tooltip" title="{{ $account-
>status == 'completed' ? 'Confirmed on ' . date('F d, Y', strtotime($account-
>confirmed_at)) : 'pending confirmation' }}" style="border: none; background:
@role('admin')
<td><a href="{{ route('staff.edit', $account-
>createdBy) }}" target="_blank">{{ $account->createdBy->name }}</a></td>
<td>
//错误指向
我已尽我所能,但没有解决办法。
请帮帮我
【问题讨论】:
-
$account->user->roles()->first()->name;如果任何->调用返回null,则该代码将中断。在您的情况下,$account->user是null,而null->roles()不起作用。您需要添加一些代码来处理它,例如if ($account->user) { // Do something with $account->user->roles()->first() }
标签: laravel