How to show table content based on the foreignId in Laravel? - php

So I have a table called pekerjaan (work) and it is in an eloquent with another table called jeniskerja (type of work), jeniskerja hasMany pekerjaan, and pekerjaan belongsTo jeniskerja... I want to show the list of the work based on the type of the work which is the foreignId when the user click on the type shown below (if the type is A it will show list of works of type A), but the problem is I already shown the table based on another foreignId, in this case it is the penyedia (vendor)... So, at the moment the table in foreach section show all the list of works based on the penyedia_id (vendor_id)... How do I create another filter whereby when the user click on the type (in this case a card header) it will expand and show the list of works table based on the type they are clicking?
Here is what my code looks like:
AdminController
public function showpenyedia(Penyedia $penyedia){
$pekerjaan = $penyedia->pekerjaans; //show pekerjaan(work) based on penyedia(vendor)
$jeniskerja = Jeniskerja::all();
return view('admin.showpenyedia', compact('penyedia','pekerjaan','jeniskerja'));
}
detailpenyedia.php (this is where the table content is)
#foreach ($jeniskerja as $jeniskerjas)
<section class="content">
<div class="container-fluid">
<div class="card card-default collapsed-card">
<div class="card-header collapsed-card">
<h3 class="card-title">
<b>{{$jeniskerjas->nama_jenis}}</b> //show the name of the type
</h3>
<div class="card-tools">
<button type="button" class="btn btn-tool" data-card-widget="collapse">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
<div class="card-body table-responsive">
<table id="tabelpekerjaan" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px" rowspan="2">Tahun Anggaran</th>
<th rowspan="2">Tanggal Kontrak</th>
<th rowspan="2">Paket Pekerjaan</th>
<th rowspan="2">Nama Perusahaan</th>
<th rowspan="2">Lokasi Pekerjaan</th>
<th rowspan="2">Jenis Pekerjaan</th>
<th rowspan="2">HPS</th>
<th rowspan="2">Nilai</th>
<th rowspan="2">Dokumen</th>
<th colspan="2">Tanggal</th>
</tr>
<tr>
<td>Tgl Buat</td>
<td>Tgl Update</td>
</tr>
</thead>
<tbody>
#php $no = 1; /*$totalNilai = 0.0;*/ #endphp
#foreach ($pekerjaan as $pekerjaans)
<tr>
<td>{{$pekerjaans->tanggal->format('Y')}}</td>
<td>{{$pekerjaans->tanggal->format('d/m/Y')}}</td>
<td>{{$pekerjaans->pekerjaan}}</td>
<td>{{$pekerjaans->penyedia->nama}}</td>
<td>{{$pekerjaans->lokasi}}</td>
<td>{{$pekerjaans->jeniskerja->nama_jenis}}</td>
<td>Rp. {{number_format($pekerjaans->hps,0,',',',')}}</td>
#php
$pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
#endphp
<td>{{$pekerjaans->nilai_total}}</td>
<td><u>{{$pekerjaans->status}}</u></td>
<td>
</td>
<td>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</section>
#endforeach
Here is how my page look like atm:

Related

Laravel On click Event Button [Enable button after upload file]

I have a table which contain two buttons, one is for uploading a file and the other one is for giving score. What I want to do is to give a condition for the second button which is the scoring button, whereby it can't be clicked (disabled) if there is no file uploaded. How can I achieve this?
Here is what my table looks like:
And here is my AdminController for the table
public function showpekerjaanppk(){
if(Auth::user()->status=='super'){
$pekerjaan = Pekerjaan::with('penyedia','user')->paginate();
return view('admin.showpekerjaan', compact('pekerjaan'));
}else{
$pekerjaan = Auth::user()->pekerjaans;
return view('admin.showpekerjaan', compact('pekerjaan'));
}
//return view('admin.showpekerjaan', compact('penyedia','pekerjaan','totalAvg'));
}
And here is my blade file for the table
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
#if (Auth::user()->status=='super')
<h3 class="card-title"><b>{{$penyedia->nama}}</b></h3> <br>
<h3 class="card-title">Nilai Total: <b>{{$totalAvg}}</b></h3>
#else
<h3 class="card-title"><b></b></h3> <br>
<h3 class="card-title"></b></h3>
#endif
<!-- /.card-header -->
<div class="card-body table-responsive">
<table id="tabelpekerjaan" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px" rowspan="2">No.</th>
<th rowspan="2">Tanggal</th>
<th rowspan="2">Paket Pekerjaan</th>
<th rowspan="2">Nama Perusahaan</th>
<th rowspan="2">Lokasi Pekerjaan</th>
<th rowspan="2">PPK</th>
<th rowspan="2">Nilai Kontrak</th>
<th rowspan="2">Nilai</th>
<th rowspan="2">BAHP</th>
<th colspan="2">Aksi</th>
</tr>
<tr>
<td>BAHP</td>
<td>Nilai</td>
</tr>
</thead>
<tbody>
#php $no = 1; /*$totalNilai = 0.0;*/ #endphp
#foreach ($pekerjaan as $pekerjaans)
<tr>
<td>{{$no++}}</td>
<td>{{$pekerjaans->tanggal}}</td>
<td>{{$pekerjaans->pekerjaan}}</td>
<td>{{$pekerjaans->penyedia->nama}}</td>
<td>{{$pekerjaans->lokasi}}</td>
<td>{{$pekerjaans->user->name}}</td>
<td>Rp. {{number_format($pekerjaans->nilai_kontrak,0,',',',')}}</td>
#php
$pekerjaans->nilai_total = $pekerjaans->nilai_1 + $pekerjaans->nilai_2 + $pekerjaans->nilai_3 + $pekerjaans->nilai_4;
#endphp
<td>{{$pekerjaans->nilai_total}}</td>
<td>{{$pekerjaans->bahp}}</td>
<td>
Upload
</td>
<td>
Penilaian //disabled untill file uploaded
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
#if (Auth::user()->status=='super')
<div class="card-footer">
Kembali
</div>
#endif
</div>
</section>
Thank you in advance.
#if(isset($pekerjaans->yourFileCulmnName))
<td>
Penilaian //disabled untill file uploaded
</td>
#endif

Separation the table and each name follows the table

I want Make Different on Table, Each table has a service name Dontt Need Loop Again Table same Group Name, Each group has the name of the service
Check : https://i.ibb.co/NTnynGq/639.png
View : Package.blade.php
<div class="pt-120 pb-120">
<div class="container">
<div class="row justify-content-center">
<div class="col-lg-12">
<div class="table-responsive--md">
<div class="services-table w-100">
<div class="service-group">
<div class="card">
#foreach($packages as $singlePackage)
<br>
<table class="table table-bordered style--two">
<thead>
<tr>
<th style="width:70%">
<span>Group Name : {{ $singlePackage->groups->name }}</span>
</th>
<th style="width:15%">
<span>#lang('Services Name')</span>
</th>
<th style="width:15%">
<span>#lang('Services Name')</span>
</th>
<th style="width:15%">
<span>#lang('Action')</span>
</th>
</tr>
</thead>
<tbody>
<tr class="block item">
<td class="word-break">{{ $singlePackage->name }}</td>
<td>
<span>{{ $singlePackage->delivery_time }}</span>
</td>
<td>
<span>{{ $singlePackage->price }}</span>
</td>
<td>
<span>{{ $singlePackage->price }}</span>
</td>
</tr>
</tbody>
</table>
#endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Package Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Package extends Model
{
protected $guarded = ['id'];
public function groups()
{
return $this->belongsTo(Group::class);
}
}
PackageController.php
public function packages()
{
$pageTitle = 'Packages';
$packages = Package::where('status', 1)->with('groups')->paginate(getPaginate());
return view('package',compact('pageTitle', 'packages'));
}
Want Separation each group has the name of the service
Option 1: You can add an ORDER BY group_id in the query
$packages = Package::where('status', 1)->with('groups')->orderBy('group_id')->paginate(getPaginate());
Option 2: You can sort by the group name in the foreach
#foreach($packages->sortBy(function ($item) { return $item->group->name; }) as $singlePackage)
or
#foreach($packages->sortBy(fn($item) => $item->group->name) as $singlePackage)
Option 3: Use the Collection's groupBy method.
<div class="card">
#foreach($packages->groupBy(function ($item) { return $item->groups->name; }) as $name => $group)
<br>
<table class="table table-bordered style--two">
<thead>
<tr>
<th style="width:70%">
<span>Group Name : {{ $name }}</span>
</th>
<th style="width:15%">
<span>#lang('Services Name')</span>
</th>
<th style="width:15%">
<span>#lang('Services Name')</span>
</th>
<th style="width:15%">
<span>#lang('Action')</span>
</th>
</tr>
</thead>
<tbody>
#foreach($group as $singlePackage)
<tr class="block item">
<td class="word-break">{{ $singlePackage->name }}</td>
<td>
<span>{{ $singlePackage->delivery_time }}</span>
</td>
<td>
<span>{{ $singlePackage->price }}</span>
</td>
<td>
<span>{{ $singlePackage->price }}</span>
</td>
</tr>
#endforeach
</tbody>
</table>
#endforeach
</div>

how to download pdf for a line from a table in laravel

i want to generate pdf from the database for 1 row in a table , the table name is "listings"
i used that script for the controller :
class CreatePdfController extends Controller
{
public function pdfForm(Request $request,$id){
$listing = Listing::findOrFail($id);
view()->share('listing',$listing);
if($request->has('download')){
$pdf = PDF::loadView('pdf_download');
return $pdf->download('pdf_download.pdf');
}
return view('show_details')->with('listing', $listing);
}
}
and for the show_details its the view where can i fetch just the data for 1 line in the table :
<div class="col-sm-8 offset-sm-2">
Download PDF
<div class="row">
<div class="col-md-12">
<div class="card">
<div class="card-header col-xs-6">
<div class="col-xs-3">
<h2>Listing Ref n° :{{$listing->id}}</h2>
{{$listing->owner->owner_lastname}}</h4>
</div>
<div class="col-xs-3">
<img src="{{ asset('/assets/images/listings/'.$listing->listing_Fimage) }}" width="120px" height="100px" alt="image" >
</div>
</div>
<div class="card-body">
<div class="col-xs-7 well">
<table id="example1" class="table table-bordered">
<thead>
<tr>
<th scope="row">listing_title:</th>
<td>{{$listing->listing_title}}</td>
</tr>
<tr>
<th scope="row">listing_type:</th>
<td>{{$listing->listing_type}}</td>
</tr>
<tr>
<th scope="row">listing_purpose:</th>
<td>{{$listing->listing_purpose}}</td>
</tr>
<tr>
<th scope="row">listing_location:</th>
<td>{{$listing->listing_location}}</td>
</tr>
<tr>
the pdf_download is the view that i want to generated as pdf :
<table id="example1" class="table table-bordered">
<thead>
<tr>
<th scope="row">listing_title:</th>
<td>{{$listing->listing_title}}</td>
</tr>
<tr>
<th scope="row">listing_type:</th>
<td>{{$listing->listing_type}}</td>
</tr>
<tr>
<th scope="row">listing_purpose:</th>
<td>{{$listing->listing_purpose}}</td>
</tr>
<tr>
<th scope="row">listing_location:</th>
<td>{{$listing->listing_location}}</td>
</tr>
<tr>
<th scope="row">listing_emirate:</th>
<td>{{$listing->listing_emirate}}</td>
</tr>
<tr>
<th scope="row">listing_community:</th>
<td>{{$listing->listing_community}}</td>
</tr>
<tr>
<th scope="row">listing_price:</th>
<td>{{$listing->listing_price}}</td>
</tr>
</table>
and the route that i passed is :
Route::get('/show_details/{id}' ,array('as'=>'show_details',
'uses'=>'CreatePdfController#pdfForm'));
the problem is i get that error and i cannot download the pdf file :
**Symfony\Component\ErrorHandler\Error\FatalError
Maximum execution time of 60 seconds exceeded
http://127.0.0.1:8000/show_details/3?download=pdf**

Shop by size using table format in PHP

I want my site to search for any product that belonged to particular size when click any size option in the table cell for desktop users but I am having two challenges
My loop for horizontal cells suppose to be incrementing from left to right like this 28D, 28DD, 28E, 28F, 28FF, 28G ...28K and then move to second line 30D --- 30k but instead it was reapeating each value 12 times horizontally like this 28D, 28D, 28D 12times and move to second line 28DD repeating it 12 times again. Please what could be the problem in my four loop?
I don't know how to put anchor tag around the table cell and how to put name = size attribute in the table cell for it to link sizeresult.php. where it will be processed by the select query
here is my code:
<div class="table-responsive"><!-- table-responsive begin -->
<table class="table table-striped table-hover" border="0" width="100%" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th class="success">
<h4 class="text-center white-text">D</h4>
</th>
<th class="info">
<h4 class="text-center white-text">DD</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">E</h4>
</th>
<th class="success">
<h4 class="text-center white-text">F</h4>
</th>
<th class="info">
<h4 class="text-center white-text">FF</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">G</h4>
</th>
<th class="success">
<h4 class="text-center white-text">GG</h4>
</th>
<th class="info">
<h4 class="text-center white-text">H</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">HH</h4>
</th>
<th class="success">
<h4 class="text-center white-text">J</h4>
</th>
<th class="info">
<h4 class="text-center white-text">JJ</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">K</h4>
</th>
</tr>
</thead>
<tbody>
<?php
$count = 12; // Number of possible cells to add at once:
$i=0;
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($dbc,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size_name = $row_sizes['size'];
$i++;
?>
<tr>
<?php for ($i = 1; $i <= $count; $i++) {
echo "
<td value='$size_name' align='center'>
$size_name
</td>";
} // End of FOR loop.
?>
</tr>
<?php } ?>
</tbody>
</table>
</div> <!-- table-responsive end -->
</form>
sizeresult.php code is this :
$size_name=$_POST['size'];
$run_products = mysqli_query($dbc,"SELECT * FROM products INNER JOIN SIZES USING (size_id) WHERE sizes.size ='%$size_name%'");
I made the following changes
$count variable and for loop completely
created block of code to format your list of items in the way you have explained in your question grouping them by 12 in each row.
based on your request of using anchor tag i added anchor tag so that when the user clicks on it it will be taken to the sizeresult.php page and the query will be processed.
I made sure that the post and get request doesn't conflict by putting the following code right above the query in sizeresult.php
if(isset($_GET['size'])){ $size_name=$_GET['size'] } else if(isset($_POST['size'])){ $size_name=$_POST['size']; }
the following in your main page
<div class="table-responsive"><!-- table-responsive begin -->
<table class="table table-striped table-hover" border="0" width="100%" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th class="success">
<h4 class="text-center white-text">D</h4>
</th>
<th class="info">
<h4 class="text-center white-text">DD</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">E</h4>
</th>
<th class="success">
<h4 class="text-center white-text">F</h4>
</th>
<th class="info">
<h4 class="text-center white-text">FF</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">G</h4>
</th>
<th class="success">
<h4 class="text-center white-text">GG</h4>
</th>
<th class="info">
<h4 class="text-center white-text">H</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">HH</h4>
</th>
<th class="success">
<h4 class="text-center white-text">J</h4>
</th>
<th class="info">
<h4 class="text-center white-text">JJ</h4>
</th>
<th class="danger">
<h4 class="text-center white-text">K</h4>
</th>
</tr>
</thead>
<tbody>
<tr>
<?php
//$count = 12; // Number of possible cells to add at once://you don't need this too.
$i=1;
$get_sizes = "select * from sizes";
$run_sizes = mysqli_query($dbc,$get_sizes);
while ($row_sizes=mysqli_fetch_array($run_sizes)){
$size_id = $row_sizes['size_id'];
$size_name = $row_sizes['size'];
if($i==12){
echo "<td align='center'><a href='product-card.php?size=$size_name' type='button' style='text-decoration:none; color:black;' class='btn btn-block'>$size_name</a></td>";
$i=1;
echo "</tr><tr>";
}
else {
echo "<td align='center'><a href='product-card.php?size=$size_name' type='button' style='text-decoration:none; color:black;' class='btn btn-block'>$size_name</a></td>";
$i++;
}
} // End of while loop.
?>
</tr>
</tbody>
</table>
</div> <!-- table-responsive end -->
<!-- </form> you can remove this FORM tag if you want -->

How to remain same pagination page on table after action

i have created a table (using datatables) and in the table a few actions. in the table i have a button to do a function "delete", also using datatables i get pagination.. So for example i am at page 5, and i want to delete a row when i click delete it refreshes the page and goes back to page no 1. How can i make it remain at page 5 after the action delete? Below are my table and controller function
viewStatistics.blade:
<table class="table table-hover demo-table-search table-responsive-block alt-table" id="tableWithSearch">
<thead>
<tr>
<th class="text-center" style="width:80px;">ID</th>
<th class="text-center">Date</th>
<th class="text-center">Question <br> Asked</th>
<th class="text-center">Low <br> Confidence</th>
<th class="text-center">No <br> Answer</th>
<th class="text-center">Missing <br> Intent</th>
<th class="text-center">Webhook <br> Fail</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
#foreach($data as $sessionID => $value)
<tr>
<td class="text-center">{{$value['identifier']}}</td>
<td class="text-center">{{date("d M", strtotime($value['dateAccess']))}}</td>
<td class="text-center">{{$value['total']}}</td> <!-- question asked -->
<td class="text-center">{{$value['low confidence']}}</td> <!-- low confidence -->
<td class="text-center">{{$value['no answer']}}</td> <!-- no answer -->
<td class="text-center">{{$value['missing intent']}}</td> <!-- missing intent -->
<td class="text-center">{{$value['webhook fail']}}</td> <!-- webhook fail -->
<td class="text-center" style="{{$value['status'] == 'Reviewed' ? 'color:green' : 'color:red'}}">
{{$value['status']}}
#if($value['status'] == 'Pending')
<input type="checkbox" name="check" class="check" value="{{$sessionID}}">
#endif
</td> <!-- status -->
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn alt-btn alt-btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Manage</button>
<ul class="dropdown-menu">
<li>
View
</li>
<li>
Delete
</li>
#if($value['status'] == 'Pending')
<li>
Mark as Done
</li>
#endif
</ul>
</div>
</td> <!-- action -->
</tr>
#endforeach
</tbody>
</table>
Controller:
public function deleteStatistics($companyID, $sessionID)
{
DiraChatLog::where('company_id', $companyID)->where('sessionID', $sessionID)->delete();
return redirect(action('AltHr\Chatbot\TrackerController#viewStatistics', compact('companyID')))->with('notification',[
'status' => 'success',
'title' => 'Statistics Deleted',
'message' => 'The Statistics have been deleted.'
]);
}
There is an option named stateSave in jquery datatables. Please check the code below:
$('#example').dataTable({ stateSave: true });

Categories