Last active
September 28, 2022 20:21
-
-
Save arif98741/a864c9b9fd8d8edaa6fbd02e8430dd31 to your computer and use it in GitHub Desktop.
Showing Data in Table as Groupwise. Its just group by after getting all data and row, colspan technique
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function expenseList() | |
{ | |
$user_info = Expenses::get()->groupBy(function($val) { | |
return Carbon::parse($val->current_month)->format('F'); | |
}); | |
return view('expense-list', compact('user_info')); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('backend_master') | |
@section('all_ex_active') | |
active | |
@endsection | |
@section('title') | |
{{ "Incomes" }} | |
@endsection | |
@section('backend_content') | |
<div class="br-mainpanel"> | |
<div class="br-pageheader pd-y-15 pd-l-20"> | |
<nav class="breadcrumb pd-0 mg-0 tx-12"> | |
<span class="breadcrumb-item active">All Expenses</span> | |
</nav> | |
</div><!-- br-pageheader --> | |
<div class="pd-x-20 pd-sm-x-30 pd-t-20 pd-sm-t-30"> | |
<h4 class="tx-gray-800 mg-b-5">All Expenses List</h4> | |
</div> | |
<div class="br-pagebody"> | |
<a style="color:#343a40; font-size:1.1rem; margin-left:20px" href="{{ route('addExpenseList') }}" | |
class="tx-18"><i class="fa fa-plus"></i> Add Expense</a> | |
<div class="br-section-wrapper"> | |
<div class="col-lg-6 mx-auto"> | |
@if (session('income_delete_message')) | |
<div class="alert alert-danger alert-dismissible fade show text-center" role="alert"> | |
<strong>{{ session('income_delete_message') }}</strong> | |
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
@endif | |
</div> | |
<div class="bd bd-gray-300 rounded table-responsive"> | |
<table class="table table-bordered"> | |
<tr> | |
<th>Month</th> | |
<th>Field Of Expense</th> | |
<th>Expense Amount</th> | |
<th>Total Expenses</th> | |
<th>Action</th> | |
</tr> | |
@php | |
$grandTotal = 0; | |
@endphp | |
@foreach ($user_info as $key=> $data) | |
@php | |
$total = 0; | |
@endphp | |
<tr class="bg-info text-white"> | |
<td colspan="5">{{ $key }}</td> | |
<td colspan="5"> <a href="#" class="btn btn-outline-danger text-white">Delete</a></td> | |
</tr> | |
@foreach ($data as $keyExpense=> $expense) | |
@php | |
$total += $expense->expense_amount; | |
@endphp | |
<tr> | |
<td style="border-bottom: 0px;"></td> | |
<td >{{ $expense->expense_field }}</td> | |
<td colspan="2">{{ $expense->expense_amount }}</td> | |
<td> | |
<a href="#" class="btn btn-outline-info">Edit</a> | |
<a href="#" class="btn btn-outline-danger">Delete</a> | |
</td> | |
</tr> | |
@endforeach | |
<tr class=""> | |
<td></td> | |
<td><span style="font-weight: 700">Total</span></td> | |
<td colspan="4"><span style="font-weight: 700">{{ $total }}</span></td> | |
</tr> | |
@php | |
$grandTotal += $total; | |
@endphp | |
@endforeach | |
<tr> | |
<td colspan="2"><span style="font-weight: 700; font-size: 16px">Total</span></td> | |
<td><span style="font-weight: 700; font-size: 16px">{{ $grandTotal }}</span></td> | |
</tr> | |
</table> | |
</div><!-- bd --> | |
</div><!-- br-section-wrapper --> | |
</div><!-- br-pagebody --> | |
<footer class="br-footer"> | |
<div class="footer-left"> | |
<div class="mg-b-2">Copyright © 2022 M Kamrul Tours & Travels. All Rights Reserved.</div> | |
</div> | |
</footer> | |
</div> | |
</div> | |
@endsection |
$user_info = Expenses::get()->groupBy(function($val) {
return Carbon::parse($val->current_month)->format('F');
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DROP TABLE IF EXISTS
expenses
;CREATE TABLE
expenses
(id
bigint(20) unsigned NOT NULL AUTO_INCREMENT,current_month
varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,expense_field
varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,expense_amount
decimal(10,2) NOT NULL DEFAULT '0.00',created_at
timestamp NULL DEFAULT NULL,updated_at
timestamp NULL DEFAULT NULL,deleted_at
timestamp NULL DEFAULT NULL,PRIMARY KEY (
id
)) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;