Can't display blank table cells in laravel - laravel-5

I've got the following code which shows my clubs fixtures/results list for upcoming games:
<div class="row">
<div class="col-md-10 col-md-offset-1">
<span id="hide" class="first">1st XV Fixtures/Results</span><span id="show">2nd XV Fixtures/Results</span>
<table class="table table-bordered table-hover">
<tr>
<th>Date</th>
<th>Venue</th>
<th>Opposition</th>
<th>Kick Off</th>
<th>Type</th>
<th>Score</th>
<th>Result</th>
</tr>
#foreach ($fixtures as $fix)
#if($fix['team'] === 1)
<tr class="clickableRow success league_table" href="{{ action('DynamicPages#match',[$fix['id']]) }}">
<td>{{ date("d/m/Y",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['venue'] }}</td>
<td>{{ $fix['opposition'] }}</td>
<td>{{ date("H:i",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['type'] }}</td>
#foreach($results as $result)
#if($result['match_id']=== $fix['id'])
#if(!empty($result['score']))
<td>{{ $result['score'] }}</td>
<td>{{ $result['result'] }}</td>
#else
<td> </td>
<td> </td>
#endif
#endif
#endforeach
</tr>
#else
<tr class="clickableRow danger merit-table" style="display:none;" href="{{ action('DynamicPages#match',[$fix['id']]) }}">
<td>{{ date("d/m/Y",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['venue'] }}</td>
<td>{{ $fix['opposition'] }}</td>
<td>{{ date("H:i",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['type'] }}</td>
#foreach($results as $result)
#if($result['match_id']=== $fix['id'])
#if(isset($result['score']))
<td>{{ $result['score'] }}</td>
<td>{{ $result['result'] }}</td>
#else
<td> </td>
<td> </td>
#endif
#endif
#endforeach
</tr>
#endif
#endforeach
</table>
</div>
</div>
I want it to show the score from the DB, but if thats blank, then just to show a blank table with a background colour. However, it's simple showing nothing so when I look at it, it shows a white space.
Can anyone help?

Related

Laravel how to display day and month only without year from date type?

I would wan to display month and data for payment_date only in a foreach loop in view.blade.php.
#foreach ($alert as $key=>$data)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ $data->payment_date }}</td>
<td><span class="badge bg-danger">{{ $data->status }}</span></td>
<td> <i class="bi bi-envelope-fill"></i>
</td>
</tr>
#endforeach
Hereby I include the datatype:
Short way (not recommended)
#foreach ($alert as $key=>$data)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ \Carbon\Carbon::createFromFormat('Y-m-d', $data->payment_date)->format('m-d') }}</td>
<td><span class="badge bg-danger">{{ $data->status }}</span></td>
<td> <i class="bi bi-envelope-fill"></i>
</td>
</tr>
#endforeach
Laravel way (Recommended)
Add cast to the eloquent model class.
protected $casts = [
'payment_date' => 'date',
];
after that you can do this
#foreach ($alert as $key=>$data)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ $data->payment_date->format('m-d') }}</td>
<td><span class="badge bg-danger">{{ $data->status }}</span></td>
<td> <i class="bi bi-envelope-fill"></i>
</td>
</tr>
#endforeach

How to calculate total column value without query by Laravel or php?

Here above I want to Calculate Buying Total and selling Total in the current month . Suppose in November I want to calculate sell row total , buying row total and buying-selling total count. How Can I do that . Please help...
**<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Product Name</th>
<th>Quantity (Stock IN)</th>
<th>Buying Total</th>
<th>Stock</th>
<th>Selling Total</th>
<th>Profit (%)</th>
</tr>
</thead>
<tbody>
#foreach($product_all as $row)
<tr>
<td>{{ $row->buying_date}}</td>
<td>{{ $row->product_name}}</td>
<td>{{ $row->stock_in }}</td>
<td>{{ $row->buying_price*$row->stock_in }}</td> *********
<td>{{ $row->total_stock }}</td>
<td>{{ $row->selling_price*($row->stock_in-$row->total_stock)}}</td> ********
<td>{{ ($row->buying_price*$row->stock_in) - ($row->selling_price*($row->stock_in-$row->total_stock)) }}</td>
</tr>
#endforeach
</tbody>
</table>**
<h4 style="color: #ff3939; text-align: center;">November Total Invest : {{ #### }} <span> Sell : {{ #### }}</span></h4>
There are 2 ways to do:
First: setting parameters
**<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
<?php
$yoursum1 = 0;
$yoursum2 = 0;
foreach($product_all as $row)
echo "<tr>
<td>{{ $row->buying_date}}</td>
<td>{{ $row->product_name}}</td>
<td>{{ $row->stock_in }}</td>
<td>{{ $row->buying_price*$row->stock_in }}</td> *********
<td>{{ $row->total_stock }}</td>
<td>{{ $row->selling_price*($row->stock_in-$row->total_stock)}}</td> ********
<td>{{ ($row->buying_price*$row->stock_in) - ($row->selling_price*($row->stock_in-$row->total_stock)) }}</td>
</tr>"
$yoursum1 += $yourvalue1;
$yoursum2 += $yourvalue2;
endforeach
echo "<tr>
<td></td>
<td>Summary</td>
<td>{{ $yoursum1}}</td>
<td>{{ $yoursum2}}</td> *********
<td>{{ $yoursum3}}</td>
<td>{{ $yoursum4}}</td> ********
<td>{{ $yoursum5 }}</td>
</tr>"
?>
</tbody>
</table>**
<h4 style="color: #ff3939; text-align: center;">November Total Invest : {{ #### }} <span> Sell : {{ #### }}</span></h4>
Second: using query to calculate and insert one row below
#foreach($product_all as $row)
<tr>
<td>{{ $row->buying_date}}</td>
<td>{{ $row->product_name}}</td>
<td>{{ $row->stock_in }}</td>
<td>{{ $row->buying_price*$row->stock_in }}</td> *********
<td>{{ $row->total_stock }}</td>
<td>{{ $row->selling_price*($row->stock_in-$row->total_stock)}}</td> ********
<td>{{ ($row->buying_price*$row->stock_in) - ($row->selling_price*($row->stock_in-$row->total_stock)) }}</td>
</tr>
#endforeach
<tr>
<td></td>
<td>Summary</td>
<td>{{ $value1 }}</td>
<td>{{ $value2 }}</td> *********
<td>{{ $value3 }}</td>
<td>{{ $value4 }}</td> ********
<td>{{ ($value5 }}</td>
</tr>
IT is advisable to keep calculations and processing out of the views. Controllers are meant to be the files where all calculations and data manipulations should be done.
//Say this is inside the controller method from which the view with data is returned as response
public function index(Request $request)
{
$product_all = Product::all();
$groupedByMonth = $product_all->groupBy(function($product) {
return \Illuminate\Support\Carbon::parse($product->date)->format('m');
});
$totals = (object) [
'buying' => $groupedByMonth->map(function($month){
return $month->sum('buying_total');
}),
'selling' => $groupedByMonth->map(function($month){
return $month->sum('selling_total');
}),
];
//Pass $totals to the view where it can be accessed as $totals->buying
}
As such the calculation/manipulation can be done in blade view between #php #endphp

Laravel Blade rendering table inside table with VueJS

I have this scenario working with Laravel blade view:
#foreach($event->drawingrequests as $drawing)
<tr>
<td>{{ $drawing->field1 }}</td>
<td>{{ $drawing->field2 }}</td>
<td>{{ $drawing->field3 }}</td>
<td>{{ $drawing->field4 }}</td>
<td>{{ $drawing->field5 }}</td>
<td>{{ $drawing->field6 }}</td>
<td>{{ $drawing->field7 }}</td>
</tr>
#if(count(drawing->childs) > 0)
<tr><td colspan="7">
<table class="table">
<tbody>
#foreach(drawing->childs as $stage)
<tr>
<td>{{ $stage->field1 }}</td>
<td>{{ $stage->field2 }}</td>
<td>{{ $stage->field3 }}</td>
<td>{{ $stage->field4 }}</td>
<td>{{ $stage->field5 }}</td>
</tr>
#endforeach
</tbody>
</table>
</td></tr>
#endif
#endforeach
I can I do it on VueJS??? The main question here in, on VueJs conditions are always connected to DOM elements.. I need to create other tr when childs > 0. And I need to check this condition on each drawing.
<tr v-for="drawing in eventdetail.event.drawingrequests">
<td>#{{ drawing.field1 }}</td>
<td>#{{ drawing.field2 }}</td>
<td>#{{ drawing.field3 }}</td>
<td>#{{ drawing.field4 }}</td>
<td>#{{ drawing.field5 }}</td>
<td>#{{ drawing.field6 }}</td>
<td>#{{ drawing.field7 }}</td>
</tr>
#if(drawing.childs > 0)
<tr>
<td colspan="7">
<table class="table">
<tbody>
<tr v-for="stage in drawing.childs">
<td>#{{ stage.field1 }}</td>
<td>#{{ stage.field2 }}</td>
<td>#{{ stage.field3 }}</td>
<td>#{{ stage.field4 }}</td>
<td>#{{ stage.field5 }}</td>
</tr>
</tbody>
</table>
</td>
</tr>
#endif
Found the solution:
<template v-for="drawing in eventdetail.event.drawingrequests">
<tr>
<td>#{{ drawing.field1 }}</td>
<td>#{{ drawing.field2 }}</td>
<td>#{{ drawing.field3 }}</td>
<td>#{{ drawing.field4 }}</td>
<td>#{{ drawing.field5 }}</td>
<td>#{{ drawing.field6 }}</td>
<td>#{{ drawing.field7 }}</td>
</tr>
<tr v-if="drawing.childs > 0">
<td colspan="7">
<table class="table">
<tbody>
<tr v-for="stage in drawing.childs">
<td>#{{ stage.field1 }}</td>
<td>#{{ stage.field2 }}</td>
<td>#{{ stage.field3 }}</td>
<td>#{{ stage.field4 }}</td>
<td>#{{ stage.field5 }}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</template>
Reference link:
Vue: Displaying nested data in a table

PDF generation using laravel

I am trying to generate a report in pdf format, I have a foreach loop which is looping though the objects, for some reason the data is not being displayed on the downloaded pdf.
any help is appreciated
here is my view page:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<table class="table table-striped">
<tr>
<th>Row No.</th>
<th>Entry ID</th>
<th>DC</th>
<th>Customer Name</th>
<th>ID No.</th>
<th>Referance No.</th>
<th>Entry Purpose</th>
<th>Time In</th>
<th>Time Out</th>
<th>Card No.</th>
<th>Cabinets</th>
<th>APC Card</th>
<th>Key</th>
</tr>
#foreach ($assignees as $assignee)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $assignee->id }}</td>
<td>{{ $assignee->datacenter }}</td>
<td>{{ $assignee->cust->idnumber }}</td>
<td>{{ $assignee->custidno}}</td>
<td>{{ $assignee->refnumber }}</td>
<td>{{ $assignee->entrypurpose}}</td>
<td>{{ $assignee->timein }}</td>
<td>{{ $assignee->timeout }}</td>
<td>{{ $assignee->cardno }}</td>
<td>{{ $assignee->cabinet }}</td>
<td>{{ $assignee->apccard }}</td>
<td>{{ $assignee->key }}</td>
</tr>
#endforeach
</table>
<div class="pull-right">
<strong> Report Generated on {{ date("d.m.Y") }} at {{date("h:i:sa")}} </strong>
</body>
</html>
here is my controller:
public function downloadPDF($id){
$assignees = assignee::latest();
$pdf = PDF::loadView('assignees.pdf', compact('assignees'));
return $pdf->download('invoice.pdf');
}
Instead of:
$assignees = assignee::latest();
Do:
$assignees = assignee::latest()->get()
Because latest() returns a QueryBuilder object not a collection, you have nothing to loopthough. You need to call get() to execute the query and return a result.
Also, slight nit-pick: classes (assignee) should be cammel case starting in a capital letter according to PSR-2 which Laravel follows.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
#if(count($assignees) > 0)
<table class="table table-striped">
<tr>
<th>Row No.</th>
<th>Entry ID</th>
<th>DC</th>
<th>Customer Name</th>
<th>ID No.</th>
<th>Referance No.</th>
<th>Entry Purpose</th>
<th>Time In</th>
<th>Time Out</th>
<th>Card No.</th>
<th>Cabinets</th>
<th>APC Card</th>
<th>Key</th>
</tr>
#foreach ($assignees as $assignee)
<tr>
<td>{{ $loop->index + 1 }}</td>
<td>{{ $assignee->id }}</td>
<td>{{ $assignee->datacenter }}</td>
<td>{{ $assignee->cust->idnumber }}</td>
<td>{{ $assignee->custidno}}</td>
<td>{{ $assignee->refnumber }}</td>
<td>{{ $assignee->entrypurpose}}</td>
<td>{{ $assignee->timein }}</td>
<td>{{ $assignee->timeout }}</td>
<td>{{ $assignee->cardno }}</td>
<td>{{ $assignee->cabinet }}</td>
<td>{{ $assignee->apccard }}</td>
<td>{{ $assignee->key }}</td>
</tr>
#endforeach
</table>
#else
<p>No data found!</p>
#endif
<div class="pull-right">
<strong> Report Generated on {{ date("d.m.Y") }} at {{date("h:i:sa")}} </strong>
</div>
</body>
</html>
Update the blade to this and check :
There is a closing </div> tag missing after the strong tag at the end
The $i is changed to $loop->index
I have added a condition to check if data exists otherwise show No data found!

Laravel Resource controller not getting delete route on amchor click

In laravel, I have resource controller :
Route::resource('/student','StudentController');
here is my view listing code :
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
Edit |
Link
</td>
</tr>
conytroller function i have :
public function destroy($id)
{
echo "ok";
}
My problem is that when I click on anchor button(delete ) it not
found the resource route for the delete what I am doing wrong here can
anyone please help me elated this.
when I click on the delete anchor it calls the show function of resource but I want the destroy function to call on click.
destroy function use DELETE method
in your blade view
#foreach($students as $model)
<tr>
<td>{{ $key + $models->firstItem() }}</td>
<td>{{ $model->name }}</td>
<td>{{ $model->email }}</td>
<td>{{ $model->roll_no }}</td>
<td>{{ $model->StudentDetail->phone }}</td>
<td>{{ $model->StudentDetail->course }}</td>
<td>{{ $model->StudentDetail->city }}</td>
<td>{{ $model->StudentDetail->state->state_name }}</td>
<td>
Edit |
DELETE
<form id="delete_form" style="display:none" action="{{ route('student.destroy',$model->id)}}" method="POST" >
{{ csrf_field() }}
<input type="hidden" name="_method" value="delete" />
</form>
</td>
</tr>
#endforeach

Resources