i have a relationship between SalesTransaction and SalesTransactionDetail, then the SalesTransactionDetailhas Relation with Produk and JenisMuatan Table.
but when i call JenisMuatan in blade.php, it give errors. the error is there is no JenisMuatan->name, but Produk->name is ok, nothing error with Produk.
here is my code :
$sales = SalesTransaction::with('Customer')->with('User')->latest()->get();
foreach ($sales as $item) {
$item['detail'] = SalesTransactionDetail::where('sales_transaction_id', $item->id)->with('Produk')->with('JenisMuatan')->get();
}
and this is how i implement in view
@for ($i = 0; $i < $sales->count(); $i++)
@for ($j = 0; $j < $sales[$i]->detail->count(); $j++)
<tr>
@if ($sales[$i]->detail->count() > 1)
@if ($j == 0)
<td style="text-align: center; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ $j > 0 ? '' : $i + 1 }}</td>
<td style="text-align: left; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ $j > 0 ? '' : "'" . $sales[$i]->invoice_number }}</td>
<td style="text-align: left; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ ($j > 0 ? '' : $sales[$i]->customer_id == null) ? 'Cash' : 'Deposit : ' . $sales[$i]->customer->name }}
</td>
<td style="text-align: right; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ $j > 0 ? '' : $sales[$i]->total_harga }}</td>
@endif
@endif
@if ($sales[$i]->detail->count() <= 1)
<td style="text-align: center; height: 20;">{{ $i + 1 }}</td>
<td style="text-align: left; height: 20;">{{ "'" . $sales[$i]->invoice_number }}</td>
<td style="text-align: left; height: 20;">
{{ $sales[$i]->customer_id == null ? 'Cash' : 'Deposit : ' . $sales[$i]->customer->name }}
</td>
<td style="text-align: right; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ $j > 0 ? '' : $sales[$i]->total_harga }}</td>
@endif
<td style="text-align: left; height: 20;">
{{ $sales[$i]->detail[$j]->produk->name }}</td>
<td style="text-align: left; height: 20;">
{{ $sales[$i]->detail[$j]->jenis_muatan->name }}</td>
<td style="text-align: right; height: 20;">
{{ $sales[$i]->detail[$j]->total_harga }}</td>
@if ($sales[$i]->detail->count() > 1)
@if ($j == 0)
<td style="text-align: left; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ $j > 0 ? '' : "'" . $sales[$i]->created_at }}</td>
@endif
@endif
@if ($sales[$i]->detail->count() <= 1)
<td style="text-align: left; height: 20;"
rowspan="{{ $j == 0 ? $sales[$i]->detail->count() : 1 }}">
{{ $j > 0 ? '' : "'" . $sales[$i]->created_at }}</td>
@endif
</tr>
@endfor
@endfor
thanks before
