Thursday, March 3, 2022

Laravel Special Query

 

$users = User::orderBy(Company::select('name')
    ->whereColumn('companies.user_id', 'users.id')
)->get();
 
date('d-m-y', strtotime($req->received_date)) 
$users = User::select('users.*')
    ->join('companies', 'companies.user_id', '=', 'users.id')
    ->orderBy('companies.name')
    ->get();
 
 $keyResult= DB::table('item_maps')
->join('suppliers','item_maps.sup_id', '=', 'suppliers.id')
->join('reqs', 'item_maps.id', '=' ,'reqs.item_id' )
->select('*')
->addselect(DB::raw('DATE_FORMAT(reqs.created_at, "%d/%m") as req_date'))
->where('order_status', 'no')
->where(function($query) use ($input){
$query->where('item_name', 'LIKE', '%'.$input.'%')
->orWhere('supplier_name', 'LIKE', '%'.$input.'%')
->orWhere('req_id', 'LIKE', '%'.$input.'%');
})
->get();
 
 
  $reqs= Req::orderBy(Item_map::select('sup_id')
->whereColumn('item_maps.id','reqs.item_id')
)
->orderBy(Item_map::select('item_name')
->whereColumn('item_maps.id','reqs.item_id')

)
->orderBy('req_id')
->where('order_status','no')
->where('outlet_name','Staff')
->get();
 
$purchase_adjustments = Purchase::where(Item::select('name')
->whereColumn('purchases.item_id', 'items.id'),"LIKE",$search)
->orWhere(Item::select('item_code')
->whereColumn('purchases.item_id', 'items.id'),"LIKE",$search)
->orderBy(Item::select('name')
->whereColumn('purchases.item_id', 'items.id'))
->paginate(10); 

No comments:

Post a Comment