i am self learner and stuck at one point. I dont know is that possible or not. Please refer image of data get in array.
I have 3 database table "animalsell", "dairyincomes" and "othersell". I sucessfully able to get required data from this. Now i want to put the same in one table in blade file( refer table image )
Controller file where i collect the data
$fiveincomedata = Dairyincome::select(
DB::raw('DATE_FORMAT(milksaledate, "%M %Y") as "month_name",SUM(totalamount) as "totalamount", max(milksaledate) as milksaledate')
)
->whereBetween('milksaledate', [Carbon::now()->subMonth(6), Carbon::now()->endOfMonth()])
->groupBy('month_name')
->orderBy('milksaledate', 'desc')
->get()->toArray();
// Income from Animal Sell
$fiveanimalselldata = Animalsell::select(
DB::raw('DATE_FORMAT(selldate, "%M %Y") as "month_name",SUM(totalamount) as "totalamount", max(selldate) as selldate')
)
->whereBetween('selldate', [Carbon::now()->subMonth(6), Carbon::now()->endOfMonth()])
->groupBy('month_name')
->orderBy('selldate', 'desc')
->get()->toArray();
// Income from Other Sell
$fiveotherselldata = Othersell::select(
DB::raw('DATE_FORMAT(saledate, "%M %Y") as "month_name",SUM(totalamount) as "totalamount", max(saledate) as saledate')
)
->whereBetween('saledate', [Carbon::now()->subMonth(6), Carbon::now()->endOfMonth()])
->groupBy('month_name')
->orderBy('saledate', 'desc')
->get()->toArray();
Blade File
<div >
<table id="incometable" style="width:100%">
<thead>
<tr>
<th>Date</th>
<th>Amount (Milk Sale)</th>
<th>Amount (Animal Sale)</th>
<th>Amount (Other Sale)</th>
<th>Total Amount </th>
</tr>
</thead>
<tbody>
@foreach ($fiveincomedata as $fivei )
<tr>
<td>{{ $fivei->month_name }}</td>
<td>{{$fivei->totalamount}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
Hope i explain my problem clearly and thanks for help in advance.
CodePudding user response:
$a1=array("red","green");
$a2=array("blue","yellow");
array_merge($a1,$a2);
or push the data into a common array.
CodePudding user response:
You can use the merge()
function.
For example:
$fiveincomedata = Dairyincome::all();
$fiveanimalselldata = Animalsell::all();
$fiveotherselldata = Othersell::all();
$merged = $fiveincomedata->merge($fiveanimalselldata);
$merged = $merged->merge($fiveotherselldata);
$array = $merged->toArray();
More information: https://laravel.com/docs/9.x/collections#method-merge