I'm trying to group to bring totals into my query that is in mysql
SELECT COUNT(*) as total
,e.descricao
FROM pedido_cliente p
INNER JOIN estabelecimentos e on e.id = p.estabelecimento_id
GROUP BY p.estabelecimento_id,descricao
What brings the following result
total | descricao
1 | spermercado
20 | mercadinho
10 | loja
In eloquent format
$totais = Pedido_cliente::with('estabelecimento')
->select(DB::raw('count(*) as total' ,'estabelecimento'),
->groupBy('estabelecimento_id')
->get()
Where estabelecimento_id
is the foreign key of column id
of table estabelecimentos
But the description column comes empty
table establishment
id | descricao
1 | Supermercado
2 | Mercadinho
3 | Loja
customer request
id | estabelecimento_id | pedido
1 | 1 | 5
2 | 3 | 4
3 | 2 | 3
Model Customer Order
class Pedido_cliente extends Model
{
protected $table = 'pedido_cliente';
public function estabelecimento() {
return $this->belongsTo('App\Estabelecimento', 'estabelecimento_id');
}
}
Template establishment
class Estabelecimento extends Model
{
}
Why is the description null?