If you use relationship it could be like this
$items = Item::with('category')->get();
<td>{{ $item->category->name }}</td>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'd like to present a list of records in a table view, if possible, utilizing one field as a link to access the details of said record.
I would like to use a couple of checkboxes and select boxes to display the data...unless it would be better to retrieve the related data and display in the table row.
<thead>
<tr>
<th>Catalog Number</th>
<th>Description</th>
<th>Stocked</th>
<th>Category</th>
<th>Review</th>
<th>In Use</th>
<th>Discontinued</th>
<th>Classification</th>
</tr>
@foreach ($items as $item)
<tr>
<td><a href="{{ $item->path() }}">{{ $item->catalogNumber }}</a></td>
<td>{{ $item->description }}</td>
<td>{{ $item->stocked == 1 ? 'Yes' : 'No'}}</td>
<td>{{ $item->category_id}}</td>
<td>{{ $item->review }}</td>
<td>{{ $item->inUse }}</td>
<td>{{ $item->discontinued }}</td>
<td>{{ $item->classification_id }}</td>
</tr>
@endforeach
</thead>
I used the ?: to change 1 and 0 to Yes and No, but how would I get a Category name instead of the id?
Thanks.
Please or to participate in this conversation.