This is controller part
$users_list = User::where('id', '>', 4)
->where('status', 1)
->orderBy('id')
->get();
$companys = WorkFor::all();
$categories = TaskCetagorys::all();
//$report_table = array();
foreach($users_list as $user){
$report_table = array();
$user_tasks = Task::select('task_date',DB::raw('group_concat(tasks.workfor_name) as workfor_name'),'taskcategory_name',DB::raw('group_concat(tasks.description SEPARATOR ",,,") as description'))
->wherebetween('task_date', array("$start_task_date", "$end_task_date"))
->where('asign_id', '=', $user->id)
->where('status', 1)
->groupBy('workfor_id')
->orderBy('task_date')
->get();
}
This is my view part
<table id = "datatable" class="table table-striped table-bordered" style="font-size: 85%">
<thead>
<tr>
<th class="bg-primary col-sm-2" >
<font size="4">
Employee
</font>
</th>
{{--<th class="bg-danger">--}}
{{--<font size="4">--}}
{{--Company--}}
{{--</font>--}}
{{--</th>--}}
{{--<th class="bg-success">--}}
{{--<font size="4">--}}
{{--Category--}}
{{--</font>--}}
{{--</th>--}}
{{--<th class="bg-warning">--}}
{{--<font size="4">--}}
{{--Task--}}
{{--</font>--}}
{{--</th>--}}
</tr>
</thead>
<tbody>
#foreach ($report_table_all as $report)
<?php
$name = $report[0]['user_name'];
$user_designation = $report[0]['user_designation'];
?>
<tr>
<td>
{{--<font size="2">--}}
<strong>{{$name}}</strong></br>
{{--</font>--}}
<font size="1">
{{$user_designation}}
</font>
</td>
<td>
#foreach ( $report as $daily_report )
<table class="table table-striped table-bordered datatable" style="font-size: 85%">
<thead>
<tr class="primary" style="font-size: 15px;">
<th class="bg-info">Concern</th>
<th class="bg-warning">Category</th>
<th class="bg-success">Task</th>
<th class="bg-danger">Date</th>
</tr>
</thead>
<?php
$total = 0;
$sn = 1;
$sn_total = '*';
?>
#foreach($daily_report['user_task_lists'] as $user_task)
<tr>
<td style="background-color: rgba(227, 255, 140, 0.98); ">
<center>{{$user_task->workfor_name}}</center>
</td>
<td>
<table class="table table-striped table-bordered datatable" style="font-size: 85%">
<tr>
<td style="font-size: 13px;background-color: rgba(19, 214, 255, 0.98)">
{{$sn}}.{{ $user_task->taskcategory_name }}
<?php $sn += floatval(1) ?>
</td>
</tr>
</table>
</td>
<td style="font-size: 12px;">
{{ $user_task->description}}
</td>
<td>
{{date('d-M-Y',strtotime($user_task->task_date))}}
</td>
</tr>
#endforeach
</table>
</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
I am using laravel 5.2 version.in my controller i fetch one column data using group_concat function.When i showing these data using view,the same name repeats many times in a row.but i want to show these repeated data only one time.for example,i fetched my workfor_name from database using group_concat.then when i showimg them the workfor_name repeats many times as PALO,PALO,PALO,PALO,PALO,PALO,PALO,PALO,PALO in a row.i want only one PALO in my row.need help.!!!
this is my view page
Add the keyword DISTINCT to your GROUP_CONCAT call.
$user_tasks = Task::select('task_date',DB::raw('group_concat(DISTINCT tasks.workfor_name) as workfor_name'),'taskcategory_name',DB::raw('group_concat(DISTINCT tasks.description SEPARATOR ",,,") as description'))
->wherebetween('task_date', array("$start_task_date", "$end_task_date"))
->where('asign_id', '=', $user->id)
->where('status', 1)
->groupBy('workfor_id')
->orderBy('task_date')
->get();
Related
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>
So in this query below im joining two tables through order_id and displaying the all the values from the user_orders table.
As per the image below I am trying to display only the order_Id rows that match the order_manager table.
public function getUserOrder(){
$sql = "SELECT user_orders.order_id,
user_orders.title, user_orders.price,
user_orders.quantity
FROM order_manager
JOIN user_orders ON order_manager.order_id = user_orders.order_id;";
$stmt = $this->connect()->prepare($sql);
$stmt->execute();
while ($result = $stmt->fetchAll()){
return $result;
}
}
I have attempted to use an if statement that appears to do something however it gives me the values that don't match order id in reverse.
<div class="container mt-5">
<?php $artworks = new Artworks(); ?>
<div class="row">
<div class="col-lg-12">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">Order ID</th>
<th scope="col">Full Name</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Orders</th>
</tr>
</thead>
<?php
$artworks->getOrder();
foreach ($artworks->getOrder() as $art) {
echo "<tbody>
<tr>
<td>$art[order_id]</td>
<td> $art[full_name]</td>
<td> $art[phone] </td>
<td>$art[address]</td>
<td>
<table class= 'tale text-center table-dark'>
<thead>
<tr>
<th scope='col'>Order ID</th>
<th scope='col'>title</th>
<th scope='col'>price</th>
<th scope='col'>Quantity</th>
</tr>
<thead>
<tbody>
<tr>";
$artworks->getUserOrder();
foreach ($artworks->getUserOrder() as $order) {
if ($order['order_id'] == $art['order_id']) {
echo "<td>$order[order_id]</td>";
}
echo "
<td>$order[title]</td>
<td>$order[price]</td>
<td>$order[quantity]</td>
</tr>";
}
echo "
</tbody>
</table>
</td>
</tr>
";
}
?>
</tbody>
</table>
</div>
</div>
</div>
Here is an image to help explain the desired output
Solved moving the td items into the if statement. Guess it was mostly correct.
$artworks->getUserOrder();
foreach($artworks->getUserOrder() as $order)
{
if ($order['order_id'] == $art['order_id']) {
echo "<td>$order[order_id]</td>";
echo "
<td>$order[title]</td>
<td>$order[price]</td>
<td>$order[quantity]</td>
</tr>
";
}
}
On my controller take data via foreach where the $upcoming->order_id is same I am checked by dd($notes) data is show but i can't get on my view php. before I am tried $note->get('amount') method it is also not working
public function index()
{ $upcomings = Booking_informations::Upcoming();
$notes = [];
foreach ($upcomings as $upcoming) {
$notes[] = Notes :: where('order_id',$upcoming->order_id)-> orderBy('id', 'ASC')->get();
};
return View('upcoming',compact('upcomings','notes',));
}
upcoming.blade.php
<table class="table table-bordered mb-0">
<tbody>
#foreach($notes as $note )
<tr>
<th scope="row">1</th>
<td>{{date('d-M-Y', strtotime($note->created_at))}}</td>
<td>{{$note->details}} </td>
<td>{{$note->amount}} </td>
</tr>
#endforeach
</tbody>
</table>
I have got answer while wrote below method have any more simple way for get results..
<table class="table table-bordered mb-0">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Content</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
#foreach($notes as $note )
#foreach($note as $id )
<tr>
<td scope="row">1</td>
<td>{{$id->details}} </td>
<td>{{$id->amount}} </td>
</tr>
#endforeach
#endforeach
</tbody>
</table>
Try referencing $note instead of $notes in your foreach loop and see if that works.
I have also noticed that you have named your view file View.blade.php. Should this be upcoming.blade.php to match the name you have provided in the returned view? Just a thought.
I am having some trouble writing some nested HTML Tables from my Laravel Collection.
My Model
public static function offers($userId)
{
return DB::table('users_vehicles')
->join('dealer_offers', 'users_vehicles.id', '=', 'dealer_offers.vehicle_id')
->where('user_id', '=', $userId)
->select('users_vehicles.*', 'dealer_offers.*');
}
My Controller
public function dash()
{
$userCars = UserVehicles::offers(Auth::user()->id)->get();
return view('customer.dash', compact('userCars'));
}
My Collection Results
In My View blade Template
#foreach( $userCars->chunk(1) as $userCarChunk)
<div id="no-more-tables">
<table class="table table-bordered table-hover">
<caption>Offers for My Mazda 326 </caption>
<thead>
<tr>
<th class="numeric">DEALER RATING</th>
<th class="numeric">AMOUNT </th>
<th class="numeric"> 3 DAYS To Accept </th>
</tr>
</thead>
<tbody>
#foreach( $userCarChunk as $car)
<tr>
<td data-title="First Name">
<div class="rating">
<label>
<input type="radio" name="rating" value="5" title="5 stars"> 5
</label>
</div>
</td>
<td data-title="Last Name"> 55 000 </td>
<td data-title="Username">
Accept
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endforeach
Front-End View
Question
How can I create a nested HTML Table for all the user vehicles, so that I can write the vehicle name and all the offers for that particular vehicle?
I hope my question is clear.
Try it like this :
<div id="no-more-tables">
<table class="table table-bordered table-hover">
<caption>Offers for My Mazda 326 </caption>
<thead>
<tr>
<th class="numeric">DEALER RATING</th>
<th class="numeric">AMOUNT </th>
<th class="numeric"> 3 DAYS To Accept </th>
</tr>
</thead>
<tbody>
#foreach( $userCars->chunk(1) as $userCarChunk)
#foreach( $userCarChunk as $car)
<tr>
<td data-title="First Name">
<div class="rating">
<label>
<input type="radio" name="rating" value="5" title="5 stars"> 5
</label>
</div>
</td>
<td data-title="Last Name"> 55 000 </td>
<td data-title="Username">
Accept
</td>
</tr>
#endforeach
#endforeach
</tbody>
</table>
</div>
Answer
My Model UserVehicles.php
public function offers() {
return $this->hasMany(DealerOffers::class, 'vehicle_id');
}
My Controller CustomerController.php
$offersToCustomer = UserVehicles::with('offers')->get();
Dashboard Blade template
#foreach( $offersToCustomer as $offer)
<div id="no-more-tables_">
<table class="table table-bordered table-hover">
<caption>Offers for My :: <b style="color: #00BFF0"> {{ $offer->vehicle_make }} {{ $offer->vehicle_model }} </b> </caption>
<thead>
<tr>
<th class="numeric">DEALER RATING</th>
<th class="numeric">AMOUNT REQUESTED </th>
<th class="numeric">AMOUNT OFFERED </th>
<th class="numeric"> Expires :: {{ Carbon\Carbon::parse($offer->offer_expiry)->format('d-m-Y') }} </th>
</tr>
</thead>
<tbody>
#foreach( $offer->offers as $subOffer)
<tr>
<td data-title="DEALER RATING">
<input id="rating" name="rating" class="rating rating-loading" value="3" data-min="0" data-max="5" data-step="1" />
</td>
<td data-title="AMOUNT REQUESTED">R {{ number_format($offer->vehicle_amount_asked, 2, '.', ' ') }} </td>
<td data-title="AMOUNT OFFERED">R {{ number_format($subOffer->offer_amount, 2, '.', ' ') }} </td>
<td data-title="ACTIONS">
<button data-offer_id="{{ $offer->id }} " data-vehicle_id="{{ $subOffer->vehicle_id }}"
class="btn btn-xs btn-success accept-offer">Accept</button>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endforeach
Output
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>