How to create subrow in one column dynamically - php

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>

Related

Get desired Data from pivot Table

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

Does not display data from database at blade.php file

i have this code in my blade.php file
<table class="table table-success table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Username</th>
<th scope="col">Password</th>
<th scope="col">Email</th>
</tr>
<tbody>
#foreach($users as $user)
<tr>
<th scope="row">{{$user->ID}}</th>
<td>{{$user->username}}</td>
<td>{{$user->password}}</td>
<td>{{$user->email}}</td>
</tr>
#endforeach
</tbody>
</table>
and when i call my blade.php file to view a html page, i see only the emails from data.
This is the view when i run a dd($user) command.
This is a Html page
Looks like you got names wrong. Try this:
<table class="table table-success table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Username</th>
<th scope="col">Password</th>
<th scope="col">Email</th>
</tr>
<tbody>
<?php
foreach($users as $user){
echo "<tr>
<th scope='row'>".$user['ID']."</th>
<td>".$user['user_login']."</td>
<td>".$user['user_pass']."</td>
<td>".$user['user_email']."</td>
</tr>";}
?>
</tbody>
</table>

My webpage list using Laravel not showing data from database

Here is the web page:
Update data and ID is showing while other data such as customer name, phone, etc are not showing.
CustomersController.php
public function index()
{
$customers = Customer::all();
return view('customers.index', ['customers' => $customers]);
}
index.blade.php
#extends('layouts.app')
#section('content')
<h1>Customers</h1>
#if(count($customers)>0)
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Updated on</th>
</tr>
</thead>
#foreach($customers as $customer)
<tbody>
<tr>
<th scope="row">{{$customer->id}}</th>
<td>{{$customer->name}}</td>
<td>{{$customer->email}}</td>
<td>{{$customer->phone}}</td>
<td>{{$customer->add}}</td>
<td>{{$customer->updated_at}}</td>
</tr>
#endforeach
#else
#endif
#endsection
You didn't close <table> and <tbody>, and you placed <tbody> inside the loop (it should only appear once)
Try this:
#extends('layouts.app')
#section('content')
<h1>Customers</h1>
#if(count($customers)>0)
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Updated on</th>
</tr>
</thead>
<tbody>
#foreach($customers as $customer)
<tr>
<td>{{$customer->id}}</td>
<td>{{$customer->name}}</td>
<td>{{$customer->email}}</td>
<td>{{$customer->phone}}</td>
<td>{{$customer->add}}</td>
<td>{{$customer->updated_at}}</td>
</tr>
#endforeach
</tbody>
</table>
#else
#endif
#endsection
You didn't close your table tag and <tbody> tag and <tbody> opening tag should be start before foreach loop.

Combine data from two mysql tables in HTML table Laravel 5.4

Trying to make one html table where is showing what login users choose.
One login auth users and one form data.
Here data is showing on page but scramled in table.
Homedata is showing twice.
Here is my index page where im trying to do:
<table class="table" id="users-info">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Naional Number</th>
<th scope="col">Device</th>
<th scope="col">Reimbursment</th>
<th scope="col">Warranty</th>
</tr>
</thead>
<tbody>
#if(count($users) > 0)
#foreach($users as $user)
<tr>
<th scope="row">{{ $user->id }}</th>
<td>{{ $user->firstname }}</td>
<td>{{ $user->lastname }}</td>
<td>{{ $user->phone }}
#foreach($homedata as $homedatas)
<td>{{$homedatas->device}}</td>
<td>{{$homedatas->reimburse_Pension}}</td>
<td>{{$homedatas->bonus_remainder}}</td>
#endforeach
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
Please help.
if there is another way please feel free suggest.
Hey everyone who share the same problem.
I add in second foreach ->slice(0, 1) and that foreach just going once, that automaticaly means no duplicate data :)

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