I have connected tables with a hasMany
& belongsTo
relationship.
Bridal Model:
public function plans()
{
return $this->hasMany("App\Plan");
}
Plan Model:
public function bridal()
{
return $this->belongsTo("App\Bridal");
}
And I have an query that returns those data to endpoint.
public function bridal()
{
$bridals = Bridal::with(["plans" => function($query){
$query->orderBy("plans.plan_price");
}])
->groupBy("place_name")
->get();
return $bridals;
}
Everything is fine, except one thing. In Bridal table some of ID doesn't have plan. So when I return datas, some of bridal id
comes with an empty Plans
array.
I want to prevent that. If a bridal id
doesn't have a plan, then I don't want to return that bridal id. How can I achieve what I want here?