Good afternoon!
lpu = this-> findByHospital_id ( id, [
'hospitals.lpu' => intval ( uid_lpu),
]
);
The first table “Hospitals” contains: ID, lpu and description.
The second Blood table contains Hospital_id
Please tell me how in the second controller I want to determine the id of the first (intval(uid_lpu)) - this is the value obtained by the post method)
The bottom line is that I need to find the id of the second table (via the condition)
Well first get some authentication and authorization setup. Next setup relations: https://book.cakephp.org/3/en/orm/associations.html
Or use a query similar to:
Not cake example but you should get the idea:
public function ownerWithPets()
{
$ownerid = $request->input('ownerid'); // passed from search
$owner = Powner::find($ownerid); // find owner (hospital)
$pets = DB::table('pets') // child table
->where('ownerid', '=', $ownerid)
->orderBy('petname', 'asc')->get();
//print_r($pets);
return view('owner/ownerpet')->with(compact('owner', 'pets'));
}
view
<!DOCTYPE html>
<html>
<head>
<title>whatever</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div><?php echo $owner->oname; ?> // the petowner (hospital)
<?php echo "<br>"; ?>
<?php echo "======================"; ?>
</div>
<div>
<?php foreach ($pets as $pet) { ?>
<?php echo $pet->petname; ?> // Child table data
<?php echo "<br>"; ?>
<?php } ?>
</div>
</body>
</html>
Just a very simplified example here. Use whatever layout, template, etc as needed.
Don’t forget to validate, sanitize the data.