Laravel Blade rendering table inside table with VueJS - laravel

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

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 change value change text in laravel

I want to when change TVA value change text But in the end, the same result
They appear "NET TTC" in both cases
Function :
public function invoice()
{
return $this->belongsTo(Invoice::class, 'invoice_id', 'id');
}
public function tvaText(){
if( $this->TVA_value == 0 ){
$this->tva_text='NET TTC';
}elseif($this->TVA_value != 0){
$this->tva_text='Total TTC';
}
return $this->tva_text;
}
Show :
#foreach($invoice->details as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->product_name }}</td>
<td>{{ $item->quantity }}</td>
<td>{{ $item->unit_price }}</td>
<td>{{ $item->row_sub_total }}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<th colspan="2">TVA value </th>
<td>{{ $invoice->TVA_value }}</td>
</tr>
<tr>
<td colspan="3"></td>
<th colspan="2">sub total</th>
<td>{{ $invoice->sub_total }}</td>
</tr>
<tr>
<td colspan="3"></td>
<th colspan="2">TVA total</th>
<td>{{ $invoice->TVA_total }}</td>
</tr>
<tr>
<td colspan="3"></td>
<th colspan="2">{{ $item->**tvaText()** }}</th>
<td>{{ $invoice->TTC_total }}</td>
</tr>
#endforeach
Please see pictures so that it becomes clear to you what I mean
does anyone know how to change text or any other method to achieve?
You can do it easily on blade.
#if($invoice->TVA_value == 0 )
<td>NET TTC</td>
#else
<td> Total TTC </td>
#endif

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

Can't display blank table cells in laravel

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?

Laravel 4 pagination - Can't get past page 1

I have created somewhat of a search feature, where a user can choose a type, pool, date and time. I can't seem to make the paginator to work, as when I click on page 2 the results disappear.
I have tried to append the $query->links() function, but none of my tries have yet succeeded.
The URL looks like this: http://localhost:8080/nih/public/bassengweb/data?time_maling=1&pool_id=1&fraDato=14%2F04%2F2014&tilDato=22%2F04%2F2014&fraTid=00%3A01&tilTid=23%3A59
The code for the view file:
#extends('default')
#section('content')
<h1>ADMIN SØK</h1>
{{ Form::open(array('url' => 'bassengweb/data', 'method' => 'GET')) }}
<table>
<tr>
<td>{{ Form::label('time_maling', 'Timemåling') }}</td>
<td>{{ Form::checkbox('time_maling', 1) }}</td>
<td>{{ Form::label('3_time_maling', '3. Timemåling') }}</td>
<td>{{ Form::checkbox('3_time_maling', 1) }}</td>
<td>{{ Form::label('oppgaver', 'Oppgaver') }}</td>
<td>{{ Form::checkbox('oppgaver', 1) }}</td>
<td>{{ Form::label('pool_id', 'Basseng') }}</td>
<td>{{ Form::select('pool_id', $pools, Input::old('pool_id')) }}</td>
</tr>
<tr>
<td>{{ Form::label('dagsoppg', 'Dagvakt') }}</td>
<td>{{ Form::checkbox('dagsoppg', 1) }}</td>
<td>{{ Form::label('kveldsoppg', 'Kveldsvakt') }}</td>
<td>{{ Form::checkbox('kveldsoppg', 1) }}</td>
<td>{{ Form::label('helgoppg', 'Helgevakt') }}</td>
<td>{{ Form::checkbox('helgsoppg', 1) }}</td>
</tr>
<tr>
<td>{{ Form::label('kontcm', 'Kontroll CM') }}</td>
<td>{{ Form::checkbox('kontcm', 1) }}</td>
<td>{{ Form::label('arduino', 'Arduino') }}</td>
<td>{{ Form::checkbox('arduino', 1) }}</td>
<td><hr/></td>
</tr>
<tr>
<td>{{ Form::label('fraDato', 'Fra dato: ') }}</td>
<td>{{ Form::text('fraDato', Input::old('fraDato'), array('placeholder' => $date)) }}</td>
<td>{{ Form::label('tilDato', 'Til dato: ') }}</td>
<td>{{ Form::text('tilDato', Input::old('tilDato'), array('placeholder' => $date)) }}</td>
</tr>
<tr>
<td>{{ Form::label('fraTid', 'Fra klokka: ') }}</td>
<td>{{ Form::text('fraTid', Input::old('fraTid'), array('placeholder' => '10:55:31')) }}</td>
<td>{{ Form::label('tilTid', 'Til klokka: ') }}</td>
<td>{{ Form::text('tilTid', Input::old('tilTid'), array('placeholder' => '10:55:31')) }}</td>
<td>{{ Form::submit('Søk') }}<td>
</tr>
</table>
{{ Form::close() }}
#if(isset($data))
<table class='table table-hover'>
<tr>
<td>ID</td>
<td>Tittel</td>
<td>Verdi</td>
<td>Ansatt ID</td>
<td>Dato</td>
<td>Tid</td>
#if($type === 'measurement')
<td>Basseng</td>
</tr>
#foreach($data as $dataItem)
<tr>
<td>{{ $dataItem->id }}</td>
<td>{{ $dataItem->measurements[0]->title }}</td>
<td>{{ $dataItem->value }}</td>
<td>{{ $dataItem->emps->user_name }}</td>
<td>{{ date('d/m/Y', strtotime($dataItem->date)) }}</td>
<td>{{ $dataItem->time }}</td>
#foreach($dataItem->measurements as $measurement)
<td>{{ $pools[$measurement->pivot->pool_id] }}</td>
#endforeach
<td>{{ HTML::linkRoute('edit_data', 'Rediger', $dataItem->id) }}</td>
<td>{{ HTML::linkRoute('delete_confirm', 'Slett', $dataItem->id) }}
</td>
</tr>
#endforeach
</table>
{{ $data->appends(array($type => 1, Input::except('page')))->links() }}
#elseif($type === 'task')
</tr>
#foreach($data as $dataItem)
<tr>
<td>{{ $dataItem->id }}</td>
<td>{{ $dataItem->tasks[0]->title }}</td>
<td>{{ $dataItem->value }}</td>
<td>{{ $dataItem->emps->user_name }}</td>
<td>{{ date('d/m/Y', strtotime($dataItem->date)) }}</td>
<td>{{ $dataItem->time }}</td>
<td>{{ HTML::linkRoute('edit_data', 'Rediger', $dataItem->id) }}</td>
<td>{{ HTML::linkRoute('delete_confirm', 'Slett', $dataItem->id) }}</td>
</tr>
#endforeach
#endif
#endif
#stop
Thanks.
You nested array withing appends method:
$data->appends(array($type => 1, Input::except('page')))->links()
// returns
array(
$type => 1,
array(
... // Input/Request params are ignored as a nested array
)
)
Change it to:
$data->appends(array_merge(array($type => 1), Input::except('page')))->links()

Resources