2016-10-27 5 views
1

ユーザーのリストに、私はアバターがあります。私がこれを書いているとき:75回ループの条件はローカルで17秒かかります

<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('[email protected]', $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('[email protected]', ['users'=>$user->slug]) !!}">{{ $user->name }}</a> 
       @else 
        <a href="{!! URL::action('[email protected]', ['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' => ['[email protected]', $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' => ['[email protected]', $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

ユーザーを取得してテンプレートを準備するにはどうすればよいですか? – tkausl

+0

これを試してください: '{{is_null($ user-> avatar)? "/images/avatar/avatar.png":$ user-> avatar}} '。他のアイデア、おそらくアバターは大きいですか? – Zl3n

+0

@ Zl3n同じ結果 –

答えて

0

avatarプロパティは別のテーブルとの関係ですか?それはforeachの中で怠惰な読み込みの問題かもしれません。

あなたはEloquent documentation怠惰熱心ロードについての詳細情報を見つけることができます。

+0

nop、アバターはUserの属性です。また、私は遅延読み込みを使用しません –

関連する問題