@lipa Implement a method on your file model that determines the appropriate image so your view stays clean:
{{ $file->icon() }}
That method would return a string like image.png or pdfdocument.png.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What is the best way to display an icon of file, based on extension?
@foreach($user->files as $file)
<tr>
<td>{!! $file->extension !!}</td>
<td>{!! $file->name !!}</td>
<td>{!! $file->created_at !!}</td>
<td>{!! $user->name !!}</td>
<td>
<a href="{!! route('files.download', [$user->id, $file->id]) !!}" class="btn btn-xs btn-success">Pobierz</a>
<a href="{!! route('files.destroy', [$user->id, $file->id]) !!}" class="btn btn-xs btn-danger">Usuń</a>
</td>
</tr>
@endforeach
What is a good way to display an icon? I supposted to use few if statements or there is better way to do this?
@if ($file->name === 'png' or $file->name === 'jpg' or $file->name === 'gif' )
<img src="image.png">
@if ($file->name === 'pdf' )
<img src="pdfdocument.png">
...
Please or to participate in this conversation.