How to generate more than specific column in Laravel Blade - laravel-5

In my case it's all about pricing table.
Usually specific column in pricing table is 3
So by default is I can create more than 3 pricing but it will break the view because the view is designed for 3 pricing column in a row.
Usually I do this in view
<Div class="row">
#foreach($products as $product)
<Div class="col">
Pricings detail goes here.
</Div>
#endforeach
</Div>
<Div class="clear break"></div>
So If pricing is 3 the view will be ok, but it will break if pricing more than 3.
How I can deal with this situation?
My logic so far is create new row and clear break class if pricings divided by 3 is decimal like this simulation.
Pricings 3 div by 3 = 1 row n 1 clear break
Pricings 4 div by 3 = 1.xx so 2 row n 2 clear break
Pricings 6 div by 3 = 2 so 2 row n 2 clear break
Pricings 8 div by 3 = 2.xx so 3 row n 3 clear break
With above logic it should not break the view.
Thanks in advance.

If I understand you correctly, you only want a maximum of 3 columns in each row, and if there are any products left you want to add them to a new row.
You would be able to do it with something like this:
<div class="row">
#foreach($products as $product)
#if($loop->index % 3 == 0)
<div class="clear break"></div>
<div class="row">
#endif
<div class="col"></div>
#endforeach
</div>
Using the loop variable (see the documentation) you can check how many times you looped. This way you can start a new row before a 4th column would be added.

Related

KendoUI Grid column not re-rendering when data changes

I have a KendoUI grid with a column named "Status" :
Problem
Upon changing the value of a cell, I trigger the saving and update the grid with new data. The rows are updating but the status column is not re-rendering.
More details about the issue
The 1st row is the filter and the remainings are the actual rows.
Filter applied => Where status = Paid.
I've modified row 3 to set the status to "Not Paid".
I've triggered the Save to the backend database, then fetch all the rows where Status = Paid and then re-assign the new data to the kendo-grid.
Expected result
We have one less row in the table because the status of row 3 has changed.
All the rows in the table have "Paid" status.
Obtained result
One less row in the table. => Good
The row 4 before is now Row 3. => Good
The status of Row 3 (ex row 4) is still "Not Paid" even though in the data obtained it is "Paid". => Error
Additional notes
The html code for the column is below.
On cell value edit, the changes are saved in a dictionary on client side. When the client clicks on the save button, all changes are sent to the backend.
Assigning the new data to the kendo-grid
The table is bound to this variable which gets updated when there're new data.
<kendo-grid
[data]="this.dataAggregative.data"
...>
...
</kendo-grid>
The template for the column
<kendo-grid-column
[editable]="true"
field="status"
title="Status">
<ng-template kendoGridFilterCellTemplate let-filter>
<drop-down-list-filter
class="k-filtercell-wrapper"
[filter]="filter"
[data]="statusFilterEntries"
textField="text"
valueField="status">
</drop-down-list-filter>
</ng-template>
<ng-template kendoGridCellTemplate let-dataItem>
<div class="toolbar-container container">
<kendo-dropdownlist
[data]="statusFilterEntries"
textField="text"
valueField="status"
(selectionChange)="statusSelectionChange($event, dataItem.id)"
[value]="statusFilterEntries[dataItem.status == statusEnum.NotPaid ? 0 : 1]">
</kendo-dropdownlist>
</div>
</ng-template>
</kendo-grid-column>
Issue fixed by updating the model locally before pushing all the changes to the backend.

Showing parent and child in one row

actually I have a table in a laravel website with data from diffrent joined database tables. But this way I get a row for every child and recurring parent data.
Instead I'd like to have one row per parent data and all childs in the same row.
Looks like a basic problem, but actually I've lost sight.
Any idea?
View:
$rechnungen=DB::select(DB::raw("
select
reintern, krenr, krebez, bnrkenn, bubelegnr, aufnr, sacktonr, sacbez, ustkenn,
TO_CHAR(round(bupbetr*(1+ustproz/100),2), '99G999D99', 'NLS_NUMERIC_CHARACTERS = '',.') as brutto,
wiebez, objktext, vektext
from RECHNUNG re
join BUCHUNG bu on bu.REKEY=re.REKEY
...
join BUCHUNGPOS bup on bup.BUKEY=bu.BUKEY and nvl(BUPARTKZ,0)=0 and bup.KREKEY is null
...
where re_status=0
order by bnr.BNRKENN, bu.BUBELEGNR
"));
Controller:
#foreach ($rechnungen as $re)
<tr>
<td></td>
<td>{{$re->wiebez}} {{$re->objktext}} {{$re->ve_ktext}}</td>
<td>{{$re->krektonr}}</td>
<td>{{$re->krebez}}</td>
<td>{{$re->bnrkenn}} {{$re->bubelegnr}}</td>
<td>{{$re->aufnr}}</td>
<td>{{$re->sacktonr}} {{$re->sacbez}}</td>
<td class="text-right">{{$re->ust_kenn}}</td>
<td class="text-right">{{$re->brutto}} €</td>
</tr>
#endforeach
Looks like you just need to create a relation Many To Many https://laravel.com/docs/5.8/eloquent-relationships#many-to-many
In an attempt to understand your issue in English:
You appear to have 3 tables:
Table BILL: Columns REKEY + various data
Table BOOKING: Columns BUKEY + REKEY + various data
Table BOOKINGPOS: Columns BUPKEY + BUKEY + various data
Where BOOKING.REKEY is a foreign key reference to BILL.REKEY and BOOKINGPOS.BUKEY is a foreign key reference to BOOKING.BUKEY.
I assume that each BILL can have multiple BOOKINGs and each BOOKING can have multiple BOOKINGPOSs.
The problem you are having is a display/view issue, not a data/model issue. In pseudo-code, you should implement your view as follows:
{{ $last_rekey="" }}
#foreach( $rows as $row )
#if( $row->rekey != $last_rekey )
#if( $last_rekey != "" )
</tr>
#endif
<tr>
<td>$row->BILLdata1</td>
<td>$row->BILLdata2</td>
...
$last_rekey=$row->rekey
#endif
<td>$row->BOOKINGdata1</td>
<td>$row->BOOKINGdata2</td>
...
<td>$row->BOOKINGPOSdata1</td>
...
#endforeach
</tr>
The idea being that whenever a row of data contains a new BILL, you start displaying a new row in the table, otherwise, you just continue adding cells to the current row.

Testimonial star rating in laravel

I have stars column in my testimonials table where is gets numbers between 1 to 5 now i want to show stars depend on the number that saves in that column. For example if number is 2 show 2 stars and if is 5 show 5 stars like that.
I know it can be done trough my model but not sure how to do it.
PS: I want to use font-awesome fa fa-star to show stars in my blade.
any idea?
UPDATE
Maybe I need to explain little more, here is my table screenshot As you see there is only 1 column named stars and it gets numbers between 1-5.
Try this in your view:
#for ($i = 0; $i < $star; $i++)
<i class="fa fa-star"></i>
#endfor
More on Laravel blade loops.

how would I add index to all returned results when using pagination

I want to give index to each result from a query, something like this
page 1
1
2
3
4
5
page 2
6
7
8
9
10
page 3
etc
How would I do that? I can't use the id from the table, and I can't use $loop->iteration to print out a the index for each result, since loop->iteration would reset for each page load if I am correct?
How would I give index to all returned results and have it work accors all the pages
You can use $loop->iteration and pagination instance methods:
($results->currentPage() - 1) * $results->perPage() + $loop->iteration

Laravel 5.2 pagination + infinite scroll duplicates

I encountered a problem with pagination in my Laravel app.
Normally, when I want to use Laravel pagination with let's say 3 rows for one page, I use Eloquent method paginate/simplePaginate in combination with method latest() like so:
//MyController.php
$posts= Post->latest()->paginate(3);
//MyView.blade.php
#foreach ($posts as $post)
{{ $post->id }}
#endforeach
{{ $posts->links() }}
So when i have 6 posts in my database and I use Laravel pagination + Infinite scroll, that becomes:
6
5 (1. page)
4
--- ('page separator')
3
2 (2. page)
1
But, if user inserts new row into database table before I reach page 2,
the collection shifts and second page of data becomes:
6
5 (1. page)
4
--- POST WITH ID 4 IS DUPLICATED BECAUSE OF SHIFT IN COLLECTION
4
3 (2. page)
2
So, for example --- if user inserts three new rows into database before I reach paginator, then the second page will output the same three table rows as my current first page, but i'd like to output the remaining table rows:
6
5 (1. page)
4
--- AT SOME TIME BEFORE PAGINATION WAS TRIGGERED, POST WITH ID '7' HAS BEEN ADDED
3
2 (2. page) - continues normally with remaining rows (pagination ignores newly added row)
1
Is there any workaround for this problem?
Thanks.
I solved this issue by asking for the first record id of the first page served
// {initial query} $records->orderBy('created_at', 'desc');
if(is_int($last_id)){
$records = $records->where('id', '<=' , $last_id);
}
$records = $records->paginate($per_page);
This way, the paginator get's records starting from that id, ignoring new records
You could try this:
$posts= Post->orderBy('id', 'desc')
->distinct()
->paginate(3);

Resources