计算列值等于给定的数组

时间:2018-01-08 20:03:09

标签: php arrays laravel laravel-5 relationship

我有一个控制器,其中一组复选框值传递给控制器​​,然后发送以执行各种任务。我的问题集中在计算数组'发货的客户的结算方式,但我不完全确定如何获得这些价值,因为我发布了一个数组并且我想要计算。

这是我的控制人员:

public function sendNow(Request $request)
    {
        $now = Carbon::now();
        $sendNowShipment = array();
        $method = array();
        $sendNowShipment = request('send');
            foreach($sendNowShipment as $SNS){
                $shipment = Shipment::findOrFail($SNS);
                if($shipment->billtoAccount->billingMethods->label == "Mail"){
                $timestamp = Carbon::now()->timestamp;
                $shipment_details = $shipment->shipment_details;
                    $path = 'temp/freightbill_'.$shipment->pro_number.'-'.$timestamp.'.pdf';
                    $sessionPath[] = $path;
                    $pdf = PDF::loadView('shipments.pdf', compact('shipment', 'shipment_details'))
                        ->save($path);
                }elseif($shipment->billtoAccount->billingMethods->label == "Email"){
                    $billToAccount =   $shipment->billtoAccount;
                    $billToAccountUsers = $billToAccount->users;
                        if ($billToAccount->primary_email){
                            $billToEmail[] = $billToAccount->primary_email;
                        }
                        if ($billToAccountUsers->count() > 0){
                            foreach ($billToAccountUsers as $billToAccountUser){
                                $billToEmail[] = $billToAccountUser->email;
                            }
                        }
                        foreach ($billToEmail as $bte){
                            Mail::to($bte)->send(new newBillToShipment($shipment));
                        }
                }
            }

        if(count($shipment->billtoAccount->billingMethods->label == "Mail") > 0){// count where shipments->customers->billingMethods = Mail) > 0
            $pdf = new PDFMerger();

            // Add 2 PDFs to the final PDF
            foreach($sessionPath as $sp){
            $pdf->addPDF($sp, 'all');
            }

            // Merge the files and retrieve its PDF binary content
            $timestamp = Carbon::now()->timestamp;
            $binaryContent = $pdf->merge('download', $timestamp."-printBatch.pdf");

            // Return binary content as response
            //return response($binaryContent)
              //  ->header('Content-type' , 'application/pdf');
            return back();
            //dd($sendNowShipment,$sendMethod);
    }
    }

如果你看这条线(稍微超过中间):

if(count($shipment->billtoAccount->billingMethods->label == "Mail") > 0){
// count where shipments->customers->billingMethods = Mail) > 0

你会发现我经历了很多关系只是为了获得" Mail"我正在寻找。

所以我想知道这是否应该通过laravel进行DB ::查询,但是我不确定如何使用给定的复选框数组执行查询我已经被POST到此控制器。< / p>

0 个答案:

没有答案