title: foreach too slow with Blade in Laravel 5.2
body: <p>I am working with Laravel 5.2 and I have a section which is responding too slow, I have detected that the big delay occurs in a foreach loop, it takes one second per row and I am listing around 100 registers which makes the site very slow. It's rare because I am displaying only 7 columns and the table has in total 213 rows which is very little having the table 16 columns.</p>
  
  <p>What can I do? This is the foreach block. It takes that long only running in the production environment</p>
  
  <pre><code>@foreach($tickets as $ticket)
            &lt;tr&gt;
              &lt;td&gt;
                {{ $ticket-&gt;id }}
              &lt;/td&gt;
              &lt;td&gt;
                {{ $ticket-&gt;creator-&gt;worksAt-&gt;nombre }}
              &lt;/td&gt;
              &lt;td&gt;
                {{ $ticket-&gt;patient-&gt;toArray()['rut'] }}
              &lt;/td&gt;
              &lt;td&gt;
                {{ $ticket-&gt;getProcessName() }}
              &lt;/td&gt;
              &lt;td&gt;
                {{ $ticket-&gt;created_at-&gt;format('d M Y') }}
              &lt;/td&gt;
              @if ($ticket-&gt;getProcessSla() == $ticket-&gt;getLatency() )
                &lt;td  class="alert-warning"&gt;
              @elseif ($ticket-&gt;getProcessSla() &lt; $ticket-&gt;getLatency() )
                &lt;td  class="alert-danger"&gt;
              @else
                &lt;td  class="alert-success"&gt;
              @endif
                {{ $ticket-&gt;getLatency() }} días
                (Límite: {{ $ticket-&gt;getProcessSla() }})
              &lt;/td&gt;
              &lt;td&gt;
                @if ( null !== Auth::user()-&gt;roles-&gt;find($ticket-&gt;getProfileId()) )
                  {{ Form::open(array('action'=&gt;'StageController@redirect')) }}
                    {{ Form::hidden('ticket_id', $ticket-&gt;cryptId()) }}
                    {{ Form::hidden('process_id', $ticket-&gt;cryptProcessId()) }}
                    {{ Form::submit('Iniciar', ['class'=&gt;'btn btn-xs btn-block btn-primary']) }}
                  {{ Form::close() }}
                @endif
              &lt;/td&gt;
            &lt;/tr&gt;
      @endforeach
  </code></pre>
  
  <p>The ticket's model is this one</p>
  
  <pre><code> &lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  use App\Http\Controllers\Controller;
  use Crypt;
  use DB;
  
  class Ticket extends Model
  {
  
  
  protected $fillable = [
    'patient_id',
    'id_empresa',
    'id_usuario',
    'requiere_clinico',
    'requiere_ept',
    'activo',
    'responsable',
  
    'ept_id',
    'clinico_id',
    'is_massive',
    'inasistente',
  
    'creacion_original',
    'ficha_id'
  
  ];
  
  
  
  
  /*
   * Relations
   */
  public function creator()
  {
    return $this-&gt;belongsTo('App\User', 'id_usuario');
    //'App\Partner', 'clinical_provider', 'id_client', 'id_provider'
  }
  
  
  public function assignedTo()
  {
    return $this-&gt;belongsTo('App\User', 'responsable', 'id');
  }
  
  public function appointment()
  {
    return $this-&gt;hasMany('App\Appointment', 'id_ticket');
  }
  
  public function annulments()
  {
    return $this-&gt;hasMany('App\Anullment');
  }
  
  public function eptCriteria()
  {
    return $this-&gt;hasOne('App\EptCriteria');
  }
  
  
  public function patient()
  {
    return $this-&gt;belongsTo('App\Patient');
  }
  
  public function enterprise()
  {
    return $this-&gt;belongsTo('App\Enterprise', 'id_empresa');
  }
  
  public function process(){
    return $this-&gt;belongsToMany('App\Process', 'flows', 'id_ticket', 'id_proceso');
  }
  
  public function witness(){
    return $this-&gt;belongsToMany('App\Witness')-&gt;withTimestamps();
  }
  
  public function documents()
  {
    return $this-&gt;hasMany('App\Document', 'id_ticket');
  }
  
  public function flows()
  {
    return $this-&gt;hasMany('App\Flow', 'id_ticket');
  }
  
  public function comments()
  {
    return $this-&gt;hasMany('App\Models\Tickets\Comment', 'ticket_id');
  }
  
  /**
   * Esto permite dejar la evidencia de cuando se envió el contacto a las empresas
   * @return [type] [description]
   */
  public function enterpriseContacts(){
    return $this-&gt;hasMany('App\Enterprisecontact');
  }
  
  public function getProcessName(){
    return \App\Process::find($this-&gt;process()-&gt;max('id_proceso'))-&gt;nombre;
  }
  
  public function getProcessDescription(){
    return \App\Process::find($this-&gt;process()-&gt;max('id_proceso'))-&gt;descripcion;
  }
  
  public function getProfileId(){
  return \App\Process::find($this-&gt;process()-&gt;max('id_proceso'))-&gt;id_perfil;
  }
  
  public function getProcessSla(){
    return \App\Process::find($this-&gt;process()-&gt;max('id_proceso'))-&gt;sla;
  }
  
  public function getLatency(){
    $created = new \Carbon\Carbon($this-&gt;created_at);
    return $created-&gt;startOfDay()-&gt;diffInDays();
  }
  public function getProcessId(){
  
    return \App\Process::find($this-&gt;process()-&gt;max('id_proceso'))-&gt;id;
  }
  
  public function getClinicalAppointment(){
    return $this-&gt;appointment()-&gt;where('tipo_citacion', '=', 1)-&gt;first()['fecha'];
  }
  
  
  public function cryptProcessId(){
    return  Crypt::encrypt($this-&gt;getProcessId());
  }
  
  public function cryptId(){
    return  Crypt::encrypt($this-&gt;id);
  }
  
  public function scopeMassive($query){
    $query-&gt;where('activo', 1)
          -&gt;where('is_massive', 1);
  }
  
  public function eptTest()
  {
    return $this-&gt;hasMany('App\EptTest');
  }
  
  public function clinicalMovements()
  {
    return $this-&gt;hasMany('App\Models\MR\Movimiento');
  }
  
  
   }
  </code></pre>