Estou fazendo o seguinte Join:
public function getStockDanger()
{
$data = DB::table('product')
->join('stock', 'product.id', '=', 'stock.product_id')
->where('stock.stock', '<=', 0)
->get();
return view(
'product.index',
[
'data' => $data,
'data_category' => $this->category->all(),
'nav' => $this->nav
]
);
}
View:
@if($data->count() > 0)
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-responsive">
<thead>
<tr>
<th class="id text-center">#</th>
<th class="text-center">Produto</th>
<th class="text-center">Quantidade</th>
<th class="text-center">Preço</th>
<th class="text-center">Ações</th>
</tr>
</thead>
<tbody>
@foreach($data as $product)
<tr>
<td class="id text-center">{{$product->id}}</td>
<td class="text-center"><a class="color-red"
href="/products/{{$product->id}}">{{$product->name}}</a></td>
<td class="text-center @if($product->stock->stock <= 0) credit_danger @else credit_ok @endif">{{$product->stock->stock}}</td>
<td class="text-center credit_ok">R$ {{$product->sale_price}}</td>
<td class="text-center">
<a title="Editar" style="margin-right: 5px; color: #3498db; font-size: 18px;"
href="/products/edit/{{$product->id}}"><i class="fa fa-pencil"
aria-hidden="true"></i></a>
<a title="Excluir" style="color: #e74c3c; font-size: 18px;"
href="/products/delete/{{$product->id}}"><i class="fa fa-trash-o"
aria-hidden="true"></i></a>
</td>
</tr>
@endforeach
</tbody>
</table>
@include('pagination.default')
</div>
</div>
@else
<div class="alert alert-empty">
<strong>Nenhum cadastro!</strong> Tabela vazia
</div>
@endif
</div>
Mas estou obtendo o seguinte erro
FatalErrorException in ac3f490a3eb54420e99fe37a225e6f129d87f36d.php line 36:
Call to a member function count() on a non-object
O que posso ter feito de errado?
product.index
.