Php 列值等于给定值的计数数组
我有一个控制器,其中一组复选框值被传递给控制器,然后被发送到控制器上执行各种任务。我的问题集中在获取阵列的发货客户的计费方法的计数上,但我不完全确定如何获取这些值,因为我正在发布一个阵列,我需要一个计数 这是我的控制器:Php 列值等于给定值的计数数组,php,arrays,laravel,laravel-5,relationship,Php,Arrays,Laravel,Laravel 5,Relationship,我有一个控制器,其中一组复选框值被传递给控制器,然后被发送到控制器上执行各种任务。我的问题集中在获取阵列的发货客户的计费方法的计数上,但我不完全确定如何获取这些值,因为我正在发布一个阵列,我需要一个计数 这是我的控制器: public function sendNow(Request $request) { $now = Carbon::now(); $sendNowShipment = array(); $method = array()
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);
}
}
如果你看这条线(中间稍过一点):
你会看到,我正在经历一系列的关系,只是为了得到我所寻找的“邮件”的价值
因此,我想知道这是否应该是通过laravel的DB::查询,但我不确定如何使用已发布到该控制器的给定复选框数组执行查询。在我的头顶,而不是将它们全部计算在内,您只需抓取第一个匹配的:
$shipping->billtoAccount->billingMethods->where('label'、'='、'Mail')->first()
在找到复选框值时返回true。这是我在检查复选框值时倾向使用的方法。可能有更快/更优化的方法,但如果有,我不知道。
if(count($shipment->billtoAccount->billingMethods->label == "Mail") > 0){
// count where shipments->customers->billingMethods = Mail) > 0