Debug School

rakesh kumar
rakesh kumar

Posted on • Updated on

How to get popular broker using broker id in laravel controller

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();
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

Output

Image description

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'));       

}
Enter fullscreen mode Exit fullscreen mode

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'));       
    }
Enter fullscreen mode Exit fullscreen mode

OUTPUT

Image description

Top comments (0)