Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 75次循环中的条件在本地需要17秒_Php_Laravel - Fatal编程技术网

Php 75次循环中的条件在本地需要17秒

Php 75次循环中的条件在本地需要17秒,php,laravel,Php,Laravel,在用户列表中,我有一个化身。当我写这篇文章时: <img src="{{ $user->avatar }}" class="img-circle img-sm"/></a> avatar}“class=”img circle img sm“/> 对于75个用户,脚本需要17秒 但当我写作时: <img src="{{ "/images/avatar/avatar.png" }}" class="img-circle img-sm"/></a&g

在用户列表中,我有一个化身。当我写这篇文章时:

<img src="{{ $user->avatar }}" class="img-circle img-sm"/></a>
avatar}“class=”img circle img sm“/>
对于75个用户,脚本需要17秒

但当我写作时:

<img src="{{ "/images/avatar/avatar.png" }}" class="img-circle img-sm"/></a>

进展很快

为什么这个属性如此耗时

在这个页面中,我从这个对象调用了很多属性,但只有这一个是耗时的…它只是字符串更多

我在拉威尔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>

{{trans('core.avatar')}
{{trans('core.username')}
{{trans('core.email')}
{{trans_choice('categories.category',1)}
{{trans('core.paid')}
{{trans('core.country')}
@can('编辑',$比赛)
{{trans('core.action')}
@恩德坎
@foreach($champions->users as$user)
{{----}}
@can('edit',$user)
@否则
@恩德坎
{{$user->email}
{{$champions->category->buildName($grades)}
@如果($user->pivot->confirm)
@否则
@恩迪夫
@can('编辑',$比赛)
{!!Form::open(['method'=>'PUT','id'=>'formConfirmTCU',
'操作'=>CompetitorController@confirmUser“,$tornament->slug,$championment->id,$user->slug]])
{!!Form::close()!!}
@否则
@恩德坎
标志}}”
alt=“{{$country->name}”/>
@can('编辑',$比赛)
{!!Form::model(null,['method'=>'DELETE','id'=>'formdeletetetecu',
'操作'=>CompetitorController@deleteUser“,$tornament->slug,$championment->id,$user->slug]])
{!!Form::close()!!}
@恩德坎
@endforeach

属性是否与另一个表有关系?这可能是
foreach
内部的延迟加载问题


您可以在中找到有关加载的惰性渴望的更多信息。

化身属性是否与另一个表有关系?这可能是
foreach
内部的延迟加载问题


你可以找到更多关于lazyeanger加载的信息。

如何获取用户并准备模板?试试这个:
{{is_null($user->avatar)?“/images/avatar/avatar.png:$user->avatar}
。另一个想法,也许阿凡达是大的?@Zl3n从索引方法同样的结果@foreach($champions->users as$user)。。。但实际上,我构建的属性比这复杂得多,而且渲染速度很快……如果你对
$champions->users
对象执行
var dump
dd
,这需要多少时间?如何获取用户并准备模板?试试这个:
{{is_null($user->avatar)?“/images/avatar/avatar.png”:$user->avatar}
。另一个想法,也许阿凡达是大的?@Zl3n从索引方法同样的结果@foreach($champions->users as$user)。。。但实际上,我构建的属性比这复杂得多,而且渲染速度很快……如果你对
$champions->users
对象执行
var dump
dd
,这需要多少时间?不,化身是用户的属性。我也不使用lazy-loadingnop,化身是用户的一个属性。我也不使用延迟加载