在用户列表中,我有一个头像。当我这样写:
<img src="{{ $user->avatar }}" class="img-circle img-sm"/></a>
75位用户的脚本需要17秒。
但是当我写道:
<img src="{{ "/images/avatar/avatar.png" }}" class="img-circle img-sm"/></a>
它很快。
为什么这个属性如此耗时?
在这个页面中,我从这个对象中调用了很多属性,但只有这个属性很耗时...它只是字符串更多......
我在Laravel 5.3
编辑:粘贴全表:
<table class="table datatable-responsive" id="table{{ $championship->id }}">
<thead>
<tr>
<th class="min-tablet text-center "
data-hide="phone">{{ trans('core.avatar') }}</th>
<th class="all">{{ trans('core.username') }}</th>
<th class="phone">{{ trans('core.email') }}</th>
<th align="center" class="phone">{{ trans_choice('categories.category',1) }}</th>
<th align="center" class="phone">{{ trans('core.paid') }}</th>
<th class="phone">{{ trans('core.country') }}</th>
@can('edit',$tournament)
<th class="all">{{ trans('core.action') }}</th>
@endcan
</tr>
</thead>
@foreach($championship->users as $user)
<?php
$arr_country = $countries->where('id', $user->country_id)->all();
$country = array_first($arr_country, null);
?>
<tr>
<td class="text-center">
{{--<a href="{!! URL::action('UserController@show', $user->slug) !!}"><img--}}
{{--src="{{ is_null($user->avatar) ? "/images/avatar/avatar.png" : $user->avatar }}" class="img-circle img-sm"/></a>--}}
</td>
<td>
@can('edit',$user)
<a href="{!! URL::action('UserController@edit', ['users'=>$user->slug] ) !!}">{{ $user->name }}</a>
@else
<a href="{!! URL::action('UserController@show', ['users'=>$user->slug] ) !!}">{{ $user->name }}</a>
@endcan
</td>
<td>{{ $user->email }}</td>
<td class="text-center">{{ $championship->category->buildName($grades)}}</td>
<td class="text-center">
@if ($user->pivot->confirmed)
<?php $class = "glyphicon glyphicon-ok-sign text-success";?>
@else
<?php $class = "glyphicon glyphicon-remove-sign text-danger ";?>
@endif
@can('edit',$tournament)
{!! Form::open(['method' => 'PUT', 'id' => 'formConfirmTCU',
'action' => ['CompetitorController@confirmUser', $tournament->slug, $championship->id,$user->slug ]]) !!}
<button type="submit"
class="btn btn-flat btnConfirmTCU"
id="confirm_{!! $tournament->slug !!}_{!! $championship->id !!}_{!! $user->slug !!}"
data-tournament="{!! $tournament->slug !!}"
data-category="{!! $championship->id !!}"
data-user="{!! $user->slug !!}">
<i class="{!! $class !!} "></i>
</button>
{!! Form::close() !!}
@else
<i class="{!! $class !!} "></i>
@endcan
</td>
<td class="text-center"><img src="/images/flags/{{ $country->flag }}"
alt="{{ $country->name }}"/></td>
@can('edit',$tournament)
<td class="text-center">
{!! Form::model(null, ['method' => 'DELETE', 'id' => 'formDeleteTCU',
'action' => ['CompetitorController@deleteUser', $tournament->slug, $championship->id,$user->slug ]]) !!}
<button type="submit"
class="btn text-warning-600 btn-flat btnDeleteTCU"
id="delete_{!! $tournament->slug !!}_{!! $championship->id !!}_{!! $user->slug !!}"
data-tournament="{!! $tournament->slug !!}"
data-category="{!! $championship->id !!}"
data-user="{!! $user->slug !!}">
<i class="glyphicon glyphicon-remove"></i>
</button>
{!! Form::close() !!}
</td>
@endcan
</tr>
@endforeach
</table>
答案 0 :(得分:0)
avatar
属性是否与另一个表有关系?它可能是foreach
内的延迟加载问题。
您可以在Eloquent documentation找到有关懒惰和渴望加载的更多信息。