In controller
$all_broker = DB::table('broker')->leftJoin('states', 'broker.state_id', '=', 'states.id')
->leftJoin('cities', 'broker.city_id', '=', 'cities.id')
->leftJoin('countries', 'broker.country_id', '=', 'countries.id')
->leftJoin('items', 'broker.id', '=', 'items.broker_id')
->select(
'broker.*',
'states.state_abbr',
'cities.city_name',
'states.state_name',
'countries.country_name'
)->groupBy('broker.id')
->orderByRaw('COUNT(items.id) DESC')
->take(9)
->get();
In blade file
<div class="row row-cols-md-4 row-cols-sm-2 row-cols-1 gx-sm-5">
<!-- Bootstrap grid template -->
<div class="row">
@foreach($all_broker as $product)
<div class="col-lg-4 col-md-4 col-sm-6 col-12 mb-4">
<div class="card h-100 d-flex flex-column">
<div class="row g-0">
<div class="col-md-4">
<img src="" }}" style="border-radius: 10px;" width="800" height="90" alt="...">
</div>
<div class="col-md-8">
<a href="{{ route('page.broker',$product->id) }}" >
<div class="card-body">
<h4 >
<b>{{ $product->broker_name }}</b></h4>
<h6>{{ $product->address }}</h6>
</div>
</a>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
Output
Get top country list
public function broker_country($country_id)
{
$all_country = DB::table('countries')->get();
$broker_country = DB::table('countries')->where('id',$country_id)->first();
$country_name=$broker_country->country_name;
$searchbroker = DB::table('broker')
->leftJoin('company', 'broker.company_id', '=', 'company.id')
->leftJoin('countries', 'broker.country_id', '=', 'countries.id')
->leftJoin('states', 'broker.state_id', '=', 'states.id')
->leftJoin('cities', 'broker.city_id', '=', 'cities.id')
->where('broker.country_id',$country_id)
->select('broker.*','company.logo','company.name','cities.city_name','countries.country_name','states.state_name')
->get();
return view('frontend.broker_country', compact('all_country','searchbroker','country_name'));
}
Get top state list
public function broker_state($state_id) {
log::info("broker broker_state hain");
log::info($state_id);
$broker_state = DB::table('states')->where('id',$state_id)->first();
$state_name=$broker_state->state_name;
$all_country = DB::table('countries')->get();
$searchbroker = DB::table('broker')
->leftJoin('company', 'broker.company_id', '=', 'company.id')
->leftJoin('countries', 'broker.country_id', '=', 'countries.id')
->leftJoin('states', 'broker.state_id', '=', 'states.id')
->leftJoin('cities', 'broker.city_id', '=', 'cities.id')
->where('broker.state_id',$state_id)
->select('broker.*','company.logo','company.name','cities.city_name','countries.country_name','states.state_name')
->get();
return view('frontend.broker_state', compact('all_country','searchbroker','state_name'));
}
OUTPUT
Top comments (0)