我如何使用laravel从另一个表关系中获取数据

时间:2018-08-18 07:19:27

标签: php laravel-5 web

我想使用不同表中的laravel显示数据,在我的情况下,我将使用两次quotation_id,它如何工作?

这是我对quotation_id的代码关注点:

public function actionDatatable(DatatableParameterClass $params)
{
    try{
        $columDescriptions = [
            0 => 'no',
            // 1 => 'quotation_id',
            1 => 'quotation_id',
            2 => 'customer_id',
            3 => 'opsi'
        ];

        $limit = $params->getLimit();
        $start = $params->getStart();
        $order =$columDescriptions[$params->getOrder()];
        $dir = $params->getDir();
        $search=$params->getSearch();
        $draw=$params->getDraw();

        $numberOfRows = SrvWorkOrderLetter::count();
        $totalFiltered = $numberOfRows;

            $srvWorkOrderLetterData = SrvWorkOrderLetter::offset($start)

            ->limit($limit)
            ->orderBy($order, $dir)
            ->get();

        $data = [];
        if(count($srvWorkOrderLetterData) > 0){
            foreach($srvWorkOrderLetterData as $num => $SrvReminderNext){
                $currentData = [];
                $currentData['no'] = $num+1;                     
                // $currentData['quotation_id'] = $SrvReminderNext->getQuotation->getCustomerVehicle->vehicle_plate_license;
                $currentData['quotation_id'] = $SrvReminderNext->getQuotation->getCustomerVehicle->getVehicle->getVehicleBrand->name;
                $currentData['customer_id'] = $SrvReminderNext->getCustomer->name;
                $currentData['opsi'] = "Detail";

                $data[] = $currentData;
            }
        }

        $jsonData = [
            "draw"            => intval($draw),
            "recordsTotal"    => intval($numberOfRows),
            "recordsFiltered" => intval($totalFiltered),
            "data"            => $data
        ];

        $response = new ResponseAttributParameterClass(200, 'Data is available', $jsonData);


    }catch(\Exception $e){
        $jsonData = [
            "draw"            => 0,
            "recordsTotal"    => 0,
            "recordsFiltered" => 0,
            "data"            => []
        ];

        $response = new ResponseAttributParameterClass(200, 'Data is available'.$e, $jsonData);
    }

    return $response->getResponse();

}

如何工作quotation_id可以使用两次?请一些身体帮助。 what I give a red mark is what I will take

0 个答案:

没有答案