my question is that how can i get max revision_number of child table and how query is written
Laravel query builder
Hello all, I am in problem with my query,can anybody help ?
my Input is
$searchBy = column_name;
$searchValue = 203;
$numRec = 5;
$sortBy = 'id';
$sortType = 'DESC';
my Query is
$parentLis = Parent::selectRaw('parents.approval_status,parents.id,
child.demurrage_id,child.child_number,child.agreement_type,child.agreement_id,
child.cargo_id,child.used_laytime_manual,child.cargo_quantity_boil_off,
child.contract_price_lng,child.total_demurrage_amount_manual'
)->when($searchBy, function($query) use($searchBy, $searchValue) {
$query->where($searchBy,'LIKE', '%'.$searchValue.'%');
})->join('reivisions as child', 'child.parent_id', '=', 'parents.id')
->orderBy($sortBy, $sortType)
->paginate($numRec);
My Output
array:12 [ "current_page" => 1 "data" => array:4 [ 0 => array:11 [ "approval_status" => "Draft" "id" => 6 "parent_id" => "6" "revision_number" => "2" "agreement_type" => "SPA" "agreement_id" => "203" "nested_id" => "805" ] 1 => array:11 [ "approval_status" => "Draft" "id" => 6 "parent_id" => "6" "revision_number" => "3" "agreement_type" => "SPA" "agreement_id" => "203" "nested_id" => "805" ] 2 => array:11 [ "approval_status" => "Draft" "id" => 6 "parent_id" => "6" "revision_number" => "3" "agreement_type" => "SPA" "agreement_id" => "203" "nested_id" => "805" ] 3 => array:11 [ "approval_status" => "Draft" "id" => 1 "parent_id" => "1" "revision_number" => "2" "agreement_type" => "SPA" "agreement_id" => "203" "nested_id" => "805" ] ] Expected Output
array:12 [
"current_page" => 1
"data" => array:4 [
0 => array:11 [
"approval_status" => "Draft"
"id" => 6
"parent_id" => "6"
"revision_number" => "3"
"agreement_type" => "SPA"
"agreement_id" => "203"
"nested_id" => "805"
]
1 => array:11 [
"approval_status" => "Draft"
"id" => 1
"parent_id" => "1"
"revision_number" => "2"
"agreement_type" => "SPA"
"agreement_id" => "203"
"nested_id" => "805"
]
]
Please or to participate in this conversation.