Get desired Data from pivot Table - php

I have three model one is pivot table (grade_studentattendances) and other model are (grades and studentattendances ). i just want to show data of student from one grade to eight grade only.
my view code is:
<table border="1">
<tr>
<th>Id</th>
<th>Full name</th>
<th>Roll no</th>
<th>Date</th>
<th>Status</th>
<th>Grade</th>
</tr>
#php
$i=1;
#endphp
#foreach($studentattendance as $item)
#php $grades=$item->Grade; #endphp
<tr>
<th>{{$item->id }}</th>
<th>{{$item->name}} </th>
<th>{{$item->roll_no}}</th>
<th>{{$item->date}}</th>
<th>{{$item-> status}}</th>
<th>
#foreach($grades as $grade)
{{$grade->class_name }}
#endforeach
</th>
</tr>
#endforeach
</table>
my controller is:
public function sattend()
{
$studentattendance=studentattendance::all();
return view('primaryhead.s_attend',compact('studentattendance'));
}
i just want to show the of students from grade one to grade eight in the form of table

Related

How to create subrow in one column dynamically

In this image this table is based on my databse "Employee" table. there is 2 part. 1st part is from "#" column to "employee type" column. 2nd part is "Leave Type" Column. This column infromation will come from "LeaveType" Table. No I want to create different type leavetype for 1 employee. It mean I want to create subrow for each parent row in this column. But I can't
here is my incomplete table code in blade file.
<table class="table table-bordered mb-0" id="myTable">
<thead class="bg-orange">
<tr class="text-light">
<th >#</th>
<th >Employee Name</th>
<th >Employee Id</th>
<th >Employee Type</th>
<th >Leave Type</th>
<th >Entitled</th>
<th >Used Leave</th>
<th >Balance</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<th scope="row">{{$loop->iteration}}</th>
<td>
{{$user->name}} <br>
#foreach($designations as $designation)
#if($designation->id === $user->designationId)
{{$designation->designationName}}
<br>
#endif
#endforeach
#foreach($departments as $department)
#if($department->id === $user->departmentId)
{{$department->departmentName}}
#endif
#endforeach
</td>
<td>{{$user->employeeId}}</td>
#foreach($designations as $designation)
#if($designation->id === $user->designationId)
<td>{{$designation->attendanceType}}</td>
<br>
#endif
#endforeach
<td>
</td>
</tr>
#endforeach
</tbody>
</table>

Undefined property: stdClass::$point

I want to display user data in table but when I display point i got the error
Undefined property: stdClass::$point (View:
C:\xampp\htdocs\Gelecek_Üyeliği_Sistemi_f\Gelecek_Üyeliği_Sistemi_f\resources\views\backend\usersaction\total.blade.php)
this is the function i use it to display the data in view
public function ViewActionUserTotal() {
$total = DB::table("action_users")
->join("users", "users.id", "action_users.user_id")
->select("users.id","users.name","users.email", DB::raw("sum(action_users.point)"))
->groupBy("users.id","users.name","users.email",)->get();
return view('backend.usersaction.total',compact('total'));
}
here is the foreach in the table
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>User Name</th>
<th>User Email</th>
<th>Total Point</th>
</tr>
</thead>
<tbody>
#foreach($total as $tot)
<tr>
<td>{{$tot->name}}</td>
<td>{{$tot->email}}</td>
<td>{{$tot->point}}</td>
</tr>
#endforeach
</tbody>
</table>
when i use dd for the data it show like that
I think you forgot to make an alias for sum query .Your query should be like this :
$total = DB::table("action_users")
->join("users", "users.id", "action_users.user_id")
->select("users.id","users.name","users.email", DB::raw("sum(action_users.point) as point"))
->groupBy("users.id","users.name","users.email",)->get();
For more :https://laravel.com/docs/7.x/database#running-queries

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 }}

The first row is not printing properly when generating PDF

I have following html code in my document for generating PDF, but resulted PDF is not generating properly.
<table border="1" class="table table-striped">
<thead>
<th>Sr No.</th>
<th>Particulars </th>
<th>Qty </th>
<th>rate </th>
<th>Amount </th>
</thead>
<tbody>
<br><br>
#foreach($data as $row)
<tr>
<td>{{ $row['temp_invoice_id'] }}</td>
<td>{{ $row['tyre_brand']." ".$row['tyre_model'] }}</td>
<td>{{ $row['quantity'] }}</td>
<td>{{ $row['rate'] }}</td>
<td>{{ $row['total'] }}</td>
</tr>
#endforeach
</tbody>
</table>
But when the PDF is generated it shows something like this I don't know why it's not generating proper PDF can anyone have solution over this problem, or we have to apply separate css for print media?
Inside thead use tr tag it is working fine.
<thead>
<th>Sr No.</th>
<th>Particulars </th>
<th>Qty </th>
<th>rate </th>
<th>Amount </th>
</thead>
use like this,
<thead>
<tr>
<th>Sr No.</th>
<th>Particulars </th>
<th>Qty </th>
<th>rate </th>
<th>Amount </th>
</tr>
</thead>
Remove the <br><br> snippet in your <tbody> they are not valid, so the browser might ignore them but maybe the PDF generator (I don't know which one you use) might not.
Also place the <th>s inside a row (<tr>)

Passing data to controller on row bases

I have a table display and each row contains a button. With this button l have to pass the id to the controller where using this Admin can view user details one by one.
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<button type="submit" class="btn btn-
default" name="viewcv"> View</button> <br>
<br>
</td>
</tr>
#endforeach
</tbody>
</table>
Please check the code , hope it helps:
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>CV</td>
</tr>
#endforeach
</tbody>
</table>
Assuming you want to pass the field "id" or change it according to your requirement.
If you want to link to a show view, try something like this:
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<a href="{{action('JobController#show', $row->id)}}" class="btn btn-default">View</button>
</td>
</tr>
#endforeach
This will create a link to a view, where you can show the data.
In your controller JobController, you must create a function that receives the data:
public function show(Request $request, $id) {
...
}
Just pass the id of the record to controller function and get the details from database.
<td>
View <br>
</td>

Categories