我遇到了问题控制器的问题。我尝试dd()仍然未定义偏移当结果存在时出错,如果有空数据我访问pdf。这段代码有什么问题请帮忙
public function getReportPerPerson(Request $request)
{
$u_id = $request->user_name;
$req_id = DB::table('ssrareq_user')
->where('user_id', $u_id)
->pluck('req_id');
$temp_particular_id = array();
$temp_quantity_req = array();
$temp_purpose = array();
$temp_date_applied = array();
$temp_quantity_issued = array();
$temp_remarks = array();
$temp_status_issue = array();
$temp_status_req = array();
$temp_item_name = array();
$temp_unit = array();
$temp_quantity =array();
$temp_category =array();
$temp_price = array();
for ($i = 0; $i < count($req_id); $i++) {
$did = DB::table('ssrareqs')->select('particular_id', 'quantity_req',
'purpose', 'date_applied', 'quantity_issued', 'remarks', 'status_issue', 'status_req')
->where('req_id', $req_id[$i])
->get();
array_push($temp_particular_id,$did[0]->particular_id);
array_push($temp_quantity_req,$did[0]->quantity_req);
array_push($temp_purpose,$did[0]->purpose);
array_push($temp_date_applied,$did[0]->date_applied);
array_push($temp_quantity_issued,$did[0]->quantity_issued);
array_push($temp_remarks,$did[0]->remarks);
array_push($temp_status_issue,$did[0]->status_issue);
array_push($temp_status_req,$did[0]->status_req);
}
for ($i =0; $i <count($req_id); $i++){
$all_id = DB::table('particulars')->select('item_name','unit','quantity','category','price')
->where('particular_id',$temp_particular_id[$i])
->get();
array_push($temp_item_name,$all_id[0]->item_name);
array_push($temp_unit,$all_id[0]->unit);
array_push($temp_quantity,$all_id[0]->quantity);
array_push($temp_category,$all_id[0]->category);
array_push($temp_price,$all_id[0]->price);
}
$row = array();
$getinfo = array();
for ($i = 0; $i<count($req_id);$i++){
$row['particular_id'] = $temp_particular_id[$i];
$row['item_name'] = $temp_item_name[$i];
$row['unit'] = $temp_unit[$i];
$row['quantity'] = $temp_quantity[$i];
$row['category']=$temp_category[$i];
$row['price']=$temp_price[$i];
$row['quantity_req']=$temp_quantity_req[$i];
$row['quantity_issued']=$temp_quantity_issued[$i];
$row['status_issue']=$temp_status_issue[$i];
$row['status_req']=$temp_status_req[$i];
$row['purpose']="nothing important";
$row['remarks']=$temp_remarks[$i];
$row['date_applied']=$temp_date_applied[$i];
$getinfo[$i] =$row;
}
dd($getinfo);
$pdf = PDF::loadView('admin.personal_result', ['getinfo' => $getinfo]);
return $pdf->stream('personal_result.admin');
}
我尝试dd仍然问题apper。但是在关闭计算机并再次打开后我也遇到了这个问题
答案 0 :(得分:0)
您应该检查查询是否有任何结果。如果没有结果,则无法访问位置0.请尝试以下操作:
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@ManyToOne
@JoinColumn(name = "departament_id")
private Departament departament;
将此用于两个循环。