Dealer.php
class Dealer extends Model
{
# Relacionamento com Medalhas
public function dealer_medalhas(){
return $this->hasMany('App\DealerMedal', 'id_concessionaria');
}
}
DealerMedal.php
class DealerMedal extends Model
{
# Relacionamento com Medalhas
public function dealer(){
return $this->belongsTo('App\Dealer');
}
}
I have a relationship that I'm doing in Laravel. This query brings all the medals that a store has. But I also want to bring the medals that the store does not have in the same query.
And separate by status, type:
SHOP 1 --- MEDAL 1 --- TEM
SHOP 1 --- MEDAL 2 --- TEM
SHOP 1 --- MEDAL 3 --- DO NOT HAVE
The way the last line is, it does not come because of the relationship.
I want them all to come.
The query:
# Pesquisar na Base de Dados a Consulta do Usuário
$consulta = Dealer::whereIdMarca($codMarca)
->whereIdCidade($codCidade)
->where('concessionaria', 'like', '%'.$concessionaria.'%')
->whereStatus(1)
->get();