Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yusuf128's avatar

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"
]

]

0 likes
3 replies
yusuf128's avatar

my question is that how can i get max revision_number of child table and how query is written

AaronGavin's avatar

Hello guys..

I want to know, are .blade templates compiled into PHP at runtime ? If so, is there a way to compile them to plain php before running the code in browser ?

Same for Php, i have heard somewhere to use some JIT compiler to convert Php code to the code it is converted, is there a JIT compiler like that? https://100001.onl/ https://1921681254.mx/ https://acc.onl/hotmail

Thank You,

Snapey's avatar

@yusuf128 I cant really see what your problem is. Its not clear how what you got is different to what was expected?

@aarongavin What has your reply got to do with this question?

Please or to participate in this conversation.