how can query in laravel with model method ? i have a counter method in city model and i want to use this in my select query in response
how can i write this ?
my City model
public function mobile()
{
return $this->hasMany(Mobile::class);
}
public function mobile_count()
{
return $this->mobile()->count();
}
my query
public function findCityWithID($id)
{
$subgroup = City::select('id', 'name', 'state_id')->where('state_id', $id)->orderBy('name')->get();
return response()->json($subgroup);
}
i want have in $subgroup each City mobile counts