【发布时间】:2019-09-25 03:49:09
【问题描述】:
如何在 Laravel 中组合 2 个变量数据。我正在尝试将 $income1 和 $income2 中的数据组合成 $income 数据显示来自 $income1 和 $income2 的所有数据
这是我的控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use App\Product;
use App\Blok;
class ProductController extends Controller
{
public function income()
{
$products = Product::all();
$income1 = \App\Pembelian::join('debitur','debitur.id','=','pembelian.debiturID')
->join('blok','blok.blok_id', '=', 'debitur.blokID')
->join('products','products.id', '=', 'blok.productID')
->get();
$income2 = \App\Pembayaran::join('angsuran','angsuran.id','=','pembayaran.angsurID')
->join('debitur','debitur.id','=','angsuran.debiturID')
->join('blok','blok.blok_id', '=', 'debitur.blokID')
->join('products','products.id', '=', 'blok.productID')
->get();
$income = collect($income1, $income2);
$income->all();
return view('income', compact('products', 'income'));
}
}
但它最终只显示 $income1 数据。
【问题讨论】: