I apologize for the messy layout of my code syntax and maybe I don't really understand how to use @forelse
and @if
in Laravel, this code result is
syntax error, unexpected 'endif' (T_ENDIF)
<tbody>
@forelse ($kaders as $kader)
<tr>
<td>{{ $kader->username }}</td>
@if($kader->status_user == '1')
<td>Admin</td>
@elseif($kader->status_user == '0')
<td>Ibu / Guest</td>
@endif
@forelse ($surveillances as $surveillance)
@if($kader->username == $surveillance->nik_ortu)
@if($surveillance->status == '1')
<td>Aktif</td>
@elseif($surveillance->status == '0')
<td>NonAKtif</td>
@endif
@endif
@endforelse
<td class="text-center">
<form onsubmit="return confirm('Apakah Anda Yakin ?');" action="{{ route('kader.destroy', $kader->id) }}" method="POST">
<a href="{{ route('kader.edit', $kader->id) }}" class="btn btn-sm btn-primary"><i class="far fa-edit"></i> EDIT</a>
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger"><i class="far fa-trash-alt"></i> HAPUS</button>
</form>
</td>
</tr>
@empty
<div class="alert alert-danger">
Data Kader belum Tersedia.
</div>
@endforelse
</tbody>
This way you can use
@if (count($records) === 1)
I have one record!
@elseif (count($records) > 1)
I have multiple records!
@else
I don't have any records!
@endif
You forgot to add @empty in @forelse loop
@forelse ($surveillances as $surveillance)
@if($kader->username == $surveillance-
>nik_ortu)
@if($surveillance->status == '1')
<td>Aktif</td>
@elseif($surveillance->status == '0')
<td>NonAKtif</td>
@endif
@endif
@empty
//HEREEEE
@endforelse
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.