samedi 11 août 2018

Laravel: if foreach is empty

I have the next form in my aplication

  <div class="form-group">
  <ul class="list-unstyled">
    <table class="table">
      <thead>
        <tr>
          <td>User ID</td>
          <td>Responsable</td>
          <td>Equipo</td>
          <td>Revision fisica</td>
          <td>Observación</td>
          <td>Revision lógica</td>
          <td>Observación</td>
        </tr>
      </thead>
      <tbody>
        @foreach($devices as $device)
        <tr>
          @if($device->user_id == $user->id and $device->status == 'active')
          <td>
            <input type="text" readonly="readonly" name="user_id[]" value="" class="form-control" >
          </td>
          <td>
            <input type="text" readonly="readonly" name="responsable[]" value="" class="form-control" >
          </td>
          <td>
            <input type="text" readonly="readonly" name="device_name[]" value="" class="form-control">
          </td>
          <td>
            <select name="physical_review[]" class="form-control">
              <option value="OK">OK</option>
              <option value="NOK">NOK</option>
            </select>
          </td>
          <td>
            
          </td>
          <td>
            <select name="logical_review[]" class="form-control">
              <option value="OK">OK</option>
              <option value="NOK">NOK</option>
            </select>
          </td>
          <td>
            
          </td>
          @endif
        </tr>
        @endforeach
      </tbody>
    </table>

    </ul>
</div>
<div class="form-group">
  
</div>

This brings all the devices associated with a specific user with if condition: $device->user_id == $user->id

But, there are users without associated devices. Then, the form should not show anything.

How to create a condition and an action when the user does not have associated devices

Aucun commentaire:

Enregistrer un commentaire