Laravel DomPDF error row not found - php

Am getting this error while generating pdf using DOMPDF
The row #2 could not be found, please file an issue in the tracker wit
I can view the output as html in my view page.But PDF is not generating am getting the above error.I have two arrays for the table headings and the results. MY code as follows:
My code:
<table width="100%" class="fullwidth border">
<thead>
<tr>
<th width="10%"></th>
<th width="10%"></th>
#foreach($selected_fields_top as $key => $value)
<th>{{ $value }}</th>
#endforeach
</tr>
</thead>
<tbody>
<table >
<tbody>
#foreach($selected_fields_left as $key => $value)
<tr><td><b>{{ $value }}</b></td>
<!-- <td> -->
#foreach($resultListLeft as $left_key => $valueArr)
#foreach($valueArr as $k => $v)
#if($v)
<table>
<tbody>
<!-- <tr> -->
#if($valueArr[$value])
<td width="10%">{{$valueArr[$value]}}</td>
#else
<td width="10%">Data not available</td>
#endif
#foreach($resultListTop as $key => $TopvalueArr)
#if($key==$left_key)
#foreach($TopvalueArr as $top_key => $top_value)
#if($top_value)
<td width="10%">{{$top_value}}</td>
#else
<td width="10%">Data not available</td>
#endif
#endforeach
#endif
#endforeach
<!-- </tr> -->
</tbody>
</table>
#endif
#endforeach
#endforeach
<!-- </td> -->
#endforeach
</tr>
</tbody>
</table>
i want to print the output like:-
Top heading1 Topheading2
Left heading 1 Left value Top value Top value
Left value Top value Top value
Left value Top value Top value
etc... etc... etc...
Left heading 2 Left value Top value Top value
Left value Top value Top value
Left value Top value Top value
etc... etc... etc...

First you have to var_dump the variable if they do contain such row.

Related

How to skip row number for particular row in php?

Here is the piece of the code, in which the counter variable is used to add the question number automatically. I want to skip the question number if the type==4(last category) which is the question heading.
#php
$counter=0;
#endphp
#foreach($questions as $question)
<tr>
<td>{{++$counter}}</td>
<td colspan=4 style="text-align:left;">{{$question->title}}</td>
</tr>
<tr>
#if($question->type==1)
#include('partials.response',['question_no'=>$question->id,'question_title'=>$question->title])
#elseif($question->type==2)
#include('partials.attendance')
#elseif($question->type==3)
#include('par`enter code here`tials.rank')
#elseif($question->type==4)
#include('partials.question-heading')
#endif
</tr>
#endforeach

Passing variable from index to controller using Laravel

I am new to using Laravel and I am currently trying to pass a variable from the index blade file to the controller in order to bring up all apparatus type fields associated with a specific apparatus code id.
I am able to access the apparatus type fields associated with the apparatus code id when I include a specific number which correlates to that apparatus code id (eg. inputting 2 brings up the apparatus type details for the apparatus code id 2, inputting 3 brings up the apparatus type details for the apparatus code id 3 etc).
However when I have tried to pass a variable relating to each individual apparatus code id using a for loop in the controller, the apparatus type loop appears to not be accessed and does not return any information. I will include snippets of my current code for clarity.
Any help or guidance with this issue would be greatly appreciated!
Controller file
public function index()
{
$apparatusCodes = ApparatusCodes::get();
foreach ($apparatusCodes as $apparatusCode){
$apparatusTypes = ApparatusTypes::where('apparatus_code_id', $apparatusCode->id)->get();
}
return view('apparatus_codes.index', compact('apparatusCodes', 'apparatusTypes'));
}
Index.blade file
<table id="datatable" class="stripe hover dt-responsive display nowrap" style="width:100%; padding-top: 1em; padding-bottom: 1em;">
<thead>
<tr>
<th>ID</th>
<th >Apparatus Code</th>
<th>Description</th>
<th>Rent</th>
<th></th>
</tr>
</thead>
<!--start of for loop-->
#foreach ($apparatusCodes as $apparatusCode)
<tbody>
<tr data-toggle="collapse" id="table{{ $apparatusCode->id}}" data-target=".table{{ $apparatusCode->id}}">
<td> {{ $apparatusCode->id}} </td>
<td>{{ $apparatusCode->apparatus_code}} </td>
<td> {{ $apparatusCode->description}}</td>
<td> {{ $apparatusCode->rent}}</td>
<td #click="isOpen = !isOpen" class="main-bg"><img class="mb-1 duration-300 h-6 w-6" :class="{'transform rotate-180' : isOpen}"
src="../img/Icon-arrow-dropdown-white.png" alt="arrow down">
</td>
<td><img class="mb-1 duration-300 h-6 w-6" :class="{'transform rotate-180' : isOpen}"
src="../img/edit-icon.svg" alt="Edit Icon">
</td>
</tr>
<tr x-show.transition.duration.300ms.origin.bottom="isOpen" x-cloak #click.away="isOpen = false" class="collapse table{{ $apparatusCode->id}}">
<td colspan="999">
<div>
<table id="datatable" class="table table-striped">
<thead>
<tr>
<th>Apparatus Code </th>
<th>Apparatus Type</th>
<th>Compensation </th>
<th>Created On </th>
<th>Created By </th>
<th></th>
#foreach ($apparatusTypes as $apparatusType)
</thead>
<tbody>
<tr>
<td>{{ $apparatusCode->apparatus_code}}</td>
<td>{{ $apparatusType->apparatus_type }}</td>
<td>{{ $apparatusType->compensation }}</td>
<td>{{ $apparatusType->created_at }}</td>
<td>{{ $apparatusType->users->name}}</td>
<td> <button type="button" class="btn btn-default btn-edit js-edit"><img class="mb-1 duration-300 ml-4 inset-0 h-6 w-6" src="/../../img/Icon-edit-gray.png" alt="edit"></button></td>
</tr>
#endforeach
</table>
</tr>
</tr>
</td>
</tbody>
#endforeach
</table>
If you have the relationships setup you could eager load the ApparatusTypes for each ApparatusCode:
$apparatusCodes = ApparatusCodes::with('appartusTypes')->get();
Then in the view you could iterate the appartusTypes of each ApparatusCode:
#foreach ($apparatusCodes as $apparatusCode)
...
#foreach ($apparatusCode->apparatusTypes as $type)
...
#endforeach
...
#endforeach
Without using the relationships you could get all the ApparatusTypes for the ApparatusCodes and then group them by apparatus_code_id:
$codes = ApparatusCodes::get();
$types = ApparatusTypes::whereIn('apparatus_code_id', $codes->pluck('id'))
->get()
->groupBy('apparatus_code_id');
Then in the view you could iterate the group that corresponds to the current Code's apparatus_code_id:
#foreach ($codes as $code)
...
#foreach ($types->get($code->id, []) as $type)
...
#endforeach
...
#endforeach
Laravel 8.x Docs - Eloquent - Relationships - Eeager Loading with
Laravel 8.x Docs - Collections - Available Methods - pluck
Laravel 8.x Docs - Collections - Available Methods - groupBy

Get sum of total amount from a table column that coming from a api

I have a api with a unique number, the number is different, so when i call api with this unique number, i get back data, i am showing data in table. the table has a column name "amount".
as its dynamic data coming from an api, i am just stucked how i can show total amount in the very bottom of the table. i am using laravel.
my code sample
<table class="table table-one">
<thead class="table-success">
<tr>
<th scope="col">Inst. No.</th>
<th scope="col">PR No.</th>
<th scope="col">PR Date</th>
<th scope="col">Prem. Amt.</th>
</tr>
</thead><!-- ends: thead -->
<tbody>
#foreach ($results['polinfo'] as $data)
#foreach ($data['poldata'] as $res)
<tr>
<th scope="row">{{$res['INSTALNO']}}</th>
<td>{{$res['PR_NO']}}</td>
<td>{{$res['PR_DATE']}}</td>
<td>{{$res['AMOUNT']}}</td>
</tr>
#endforeach
#endforeach
</tbody><!-- ends: tbody -->
</table>
i have to calcualte all {{$res['AMOUNT']}} and have to show it as total amount.
Thanks in advance.
If you need the value only after the foreach you can get away with a separate variable to which to add the amounts:
#php($amount = 0)
#foreach ($results['polinfo'] as $data)
#foreach ($data['poldata'] as $res)
<tr>
<th scope="row">{{$res['INSTALNO']}}</th>
<td>{{$res['PR_NO']}}</td>
<td>{{$res['PR_DATE']}}</td>
<td>{{$res['AMOUNT']}}</td>
</tr>
#php($amount += (int) $res['AMOUNT'])
#endforeach
#endforeach
Amount: {{ $amount }}

Styling table in Laravel

I have a problem with #foreach in my blade.php. When I insert movie with multiple categories my other moves to the right. Here is how it looks in browser
and here is code in blade
#if($movies)
<div class="row">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Categories</th>
<th>Actors</th>
</tr>
</thead>
<tbody>
#foreach($movies as $movie)
<tr>
<td>{{$movie->name}}</td>
#foreach($movie->categories as $category)
<td>{{$category->category_name}}</td>
#endforeach
#foreach($movie->actors as $actor)
<td>{{$actor->actor_name}}</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
#endif
Your issue lies here:
#foreach($movie->categories as $category)
<td>{{$category->category_name}}</td>
#endforeach
You are saying that for each category, it should insert a new <td> into you table. This will of course skew the content since your table expects a set number of columns.
Instead, you should move your foreach statement inside the <td></td>
<td>
#foreach($movie->categories as $category)
{{$category->category_name}}
#endforeach
</td>
This will print the links for each category in the same column.

Create HTML table with headers in a vertical column dynamically with laravel?

I've been hunting around, but all the answers and documentation on this is for tables that aren't dynamically generating everything.
This is my blade file:
#extends('layout')
#section('content')
<h1>User Profile Data</h1>
<table class="table table-striped">
<tr>
#foreach ($columns as $column => $name)
<th><strong> {{ $name }} </strong></th>
#endforeach
#foreach ($profile as $person)
#foreach ($person as $name)
<td> {{ $name }} </td>
#endforeach
#endforeach
</tr>
</table>
#stop
It's all working, except for one problem, the heads go horizontally, rather than vertically. I'd like to be able to automatically populate the data from the database and have it displayed side by side.
Like so:
Name: John
Age: 25
Height: 176
etc.
What am I missing?
v.1 Directly generate the vertical headers table.
This can be easily solved after you realize how your table will actually look like in HTML, in order to have vertical headers.
<h1>User Profile Data</h1>
<table class="table table-striped">
<tr>
<th><strong> Name: </strong></th>
<td> John </td>
<td> Joane </td>
</tr>
<tr>
<th><strong> Surname: </strong></th>
<td> Doe </td>
<td> Donald </td>
</tr>
<tr>
<th><strong> Email: </strong></th>
<td> john.doe#email.com </td>
<td> jane#email.com </td>
</tr>
</table>
After you know your above goal you just have to nest the foreach loops so that you can populate the data.
For each column you'll have to return the matching data from the profile.
Instead of returning $person->name use $person[$col]
To nest the foreach use the same technique for your other question:
How to show data from (multidimensional?) arrays with Laravel 5.3 blade
v.2 Use normal tables combined with CSS tricks to reflow table
Import twitter bootstrap and use .table-reflow on a well formed table.
The generated table will look like this and can be generated with your initial laravel code:
<table class="table table-striped table-hover table-reflow">
<thead>
<tr>
<th ><strong> Name: </strong></th>
<th ><strong> Surname: </strong></th>
<th ><strong> Email: </strong></th>
</tr>
</thead>
<tbody>
<tr>
<td> John </td>
<td> Doe </td>
<td> john.doe#email.com </td>
</tr>
<tr>
<td> Joane </td>
<td> Donald </td>
<td> jane#email.com </td>
</tr>
</tbody>
</table>
Content order and complex tables:
Beware that the table-reflow style changes the visual order of content. Make sure that you only apply this style to well-formed and simple data tables (and in particular, don’t use this for layout tables) with appropriate <th> table header cells for each row and column.
In addition, this class will not work correctly for tables with cells that span multiple rows or columns (using rowspan or colspan attributes).
You should check the docs here:
twitter-bootstrap .table-reflow
Edit:
In addition to Kronmark's excellent points, I'm leaving this here for new people. This is what the automated table might look like:
<table class="table table-striped table-hover table-reflow">
#foreach($array as $key=>$value)
<tr>
<th ><strong> {{ $key }}: </strong></th>
<td> {{ $value }} </td>
</tr>
#endforeach
</table>
The key is the title from the table, the value is the data point associated with it. I.e. Full_Name = Key, John Magsson = value.
This is produced from an array, the process should be explained here:
Blade view not printing data from array
Good luck. :)

Categories