Return view (Table) from controller laravel - ajax

i am returning table view from controller function and its working (through ajax). but want to use foreach in above the 'tr' tag. but don't know how to use it.
Function for return Ajax response
public function displaySearch(Request $request)
{
$result = Team::where('name', $request->somthing)
->orwhere('order_id', $request->filter)->get();
$data = $this->make_ui($result);
return $data;
}
Private Function for Make UI
private function make_ui($result){
$data='';
foreach($result as $c){
$data.='<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td>'. $c->id .'</td>
<td>'. $c->order_id .'</td>
<td>'. $c->name .'</td>
<td>'. $c->role .'</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</tfoot>
</table>
</div>';
}
return $data;
}

plz use this it`s work for me
private function make_ui($result){
$data='<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>';
foreach($result as $c){
$data.='
<tr class="gradeX">
<td>'. $c->id .'</td>
<td>'. $c->order_id .'</td>
<td>'. $c->name .'</td>
<td>'. $c->role .'</td>
</tr>
';
}
$data .= '</tbody>
<tfoot>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</tfoot>
</table>
</div>';
return $data;
}

A simple solution would be to concat them separately. Though I am not sure if it's the best solution or not. you can try like below:
private function make_ui($result){
$data.='<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</thead>
<tbody>';
foreach($result as $c){
$data.='<tr class="gradeX">
<td>'. $c->id .'</td>
<td>'. $c->order_id .'</td>
<td>'. $c->name .'</td>
<td>'. $c->role .'</td>
</tr>';
}
$data.='</tbody>
<tfoot>
<tr>
<th>Action</th>
<th>ID</th>
<th>Date</th>
<th>Description</th>
</tr>
</tfoot>
</table>
</div>';
return $data;
}

Related

Formating View in maatwebsite Excel Export

I am new to maatwebsite Excel Export i am using view Excel Export in laravel and would like to know how one can specify the cell number where the data should go like a h1 tag like below snippet
<h5>PURCHASE ORDER</h5>
<hr>
<div class="container-flow">
<table id="table" class="table table-hover table-bordered table-sm text-center">
<thead>
<tr>
<th scope="col">No.</th>
<th scope="col">Product_Code</th>
<th scope="col"> Item_Description </th>
<th scope="col">Qty</th>
<th scope="col">Unit Price</th>
<th scope="col" >Value</th>
<th scope="col">Stock Less 90 Days</th>
<th scope="col">Stock More 90 Days</th>
when i export i get this
i would like to specify the cell where that tag should go like say cell B3 instead of current position cell A1
You can put some empty tags / cells before.
Try
<table>
<tr></tr>
<tr></tr>
<tr>
<td></td>
<td></td>
<td><h5>PURCHASE ORDER</h5></td>
</tr>
</table>
<hr>
<div class="container-flow">
<table id="table" class="table table-hover table-bordered table-sm text-center">
<thead>
<tr>
<th scope="col">No.</th>
<th scope="col">Product_Code</th>
<th scope="col"> Item_Description </th>
<th scope="col">Qty</th>
<th scope="col">Unit Price</th>
<th scope="col" >Value</th>
<th scope="col">Stock Less 90 Days</th>
<th scope="col">Stock More 90 Days</th>

Laravel Livewire checkbox checked on edit page

I'm facing an issue with checking the checkbox on the edit page using Livewire. I've tried many ways but still not able to check the old selected value
View Code:
<table id="branches" class="table table-bordered table-sm" width="100%" cellspacing="0">
<thead>
<tr>
<th width="10%">
</th>
<th>Branch ID</th>
</tr>
</thead>
<tbody>
#foreach ($propertiesOptions as $key => $property)
<tr>
<td>
<input class="branchCheckbox"
type="checkbox"
wire:model="propertyIds.{{$property->id}}"
value="{{$property->id}}" #if(in_array($property->id,$propertyIds)) checked #endif>
</td>
<td>{{$property->id}}</td>
</tr>
#endforeach
</tbody>
</table>
Backend Code:
public $propertyIds, $propertiesOptions;
public function mount($record)
{
$this->propertiesOptions = Properties::where('merchant_id',$record->id)->get()
$this->propertyIds = $record->properties->pluck('property_id')->toArray();
}```
updated
And can you check if this correct? wire:model="propertyIds.{{$property->id}}"? Try to delete the wire:model .
<input class="branchCheckbox" type="checkbox"
value="{{$property->id}}"
#if(in_array($property->id,$propertyIds)) checked #endif>
`<table id="branches" class="table table-bordered table-sm" width="100%" cellspacing="0">
<thead>
<tr>
<th width="10%">
</th>
<th>Branch ID</th>
</tr>
</thead>
<tbody>
#foreach ($propertiesOptions as $key => $property)
<tr>
<td>
<input class="branchCheckbox"
type="checkbox"
wire:model="propertyIds"
value="{{$property->id}}" >
</td>
<td>{{$property->id}}</td>
</tr>
#endforeach
</tbody>
</table>`
BACKEND
public $propertyIds, $propertiesOptions;
public function mount($record)
{
$this->propertiesOptions = Properties::where('merchant_id',$record->id)->get()
$this->propertyIds = $record->properties->pluck('property_id')->toArray();
}

How to Display the results in a table format [duplicate]

This question already has answers here:
Horizontal table layout using CSS
(4 answers)
Closed 2 years ago.
I want to display the result of the permissions table in a table format... I'm using Laratrust for roles and permissions
my RoleController
public function show($id)
{
$role = Role::with('permissions')->with('users')->where('id', $id)->first();
return view('admin.roles.show', compact('role'));
}
I want the results to be display in this table horizontally like the way I hard-coded it
show.blade.php
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">PERMISSION</th>
<th scope="col">CREATE</th>
<th scope="col">READ</th>
<th scope="col">UPDATE</th>
<th scope="col">DELETE</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="col">Users</th>
<td>Create User</td>
<td>Read User</td>
<td>Update User</td>
<td>Delete User</td>
</tr>
<tr>
<th scope="col">Profile</th>
<td>Create Profile</td>
<td>Read Profile</td>
<td>Update Profile</td>
<td>Delete Profile</td>
</tr>
</tbody>
</table>
<thead class="thead-dark">
<tr>
<th scope="col">PERMISSION</th>
<th scope="col">CREATE</th>
<th scope="col">READ</th>
<th scope="col">UPDATE</th>
<th scope="col">DELETE</th>
</tr>
</thead>
<tbody>
#foreach($role as $key => $data)
<tr>
<th>{{$data->permission}}</th>
<th>{{$data->create}}</th>
<th>{{$data->read}}</th>
<th>{{$data->update}}</th>
<th>{{$data->delete}}</th>
</tr>
#endforeach
</tbody>
I think this should work if role variable have all the data
You can read in Laravel docs for more information https://laravel.com/docs/8.x/eloquent-relationships#eager-loading
And make sure in your Role model has permissions, users relationship then try this:
// controller file
public function show($id)
{
$role = Role::with(['permissions', 'users'])->where('id', $id)->first();
return view('admin.roles.show', compact('role'));
}
// blade file
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">PERMISSION</th>
<th scope="col">CREATE</th>
<th scope="col">READ</th>
<th scope="col">UPDATE</th>
<th scope="col">DELETE</th>
</tr>
</thead>
<tbody>
#foreach($role->permissions as $permission)
<tr>
<th scope="col">{{ $permission->name }}</th>
<td>Create User</td>
<td>Read User</td>
<td>Update User</td>
<td>Delete User</td>
</tr>
#endforeach
</tbody>
</table>

"How to make a header fixed while content is scrolled in jquery bootgrid "

I am trying to make header fixed while the main content is scrolled in jquery bootgrid. how to make header fixed in its position?.
here is my code
<div class="table-responsive" style="display:block;height:500px;overflow:scroll ;width:100%;">
<table id="grid-data" class="table table-bordered table-sm table-striped table-hover " data-selection="true" data-multi-select="true" data-row-select="true" data-keep-selection="true">
<thead>
<tr>
<th data-column-id="ItemCode" data-sortable="false">Item Code</th>
<th data-column-id="ItemDescription" data-sortable="false">Item Description</th>
<th data-column-id="UnitName" data-formatter="UnitName" data-sortable="false">Unit Name</th>
<th data-column-id="QOH" data-formatter="Quantity" data-sortable="false">Quantity</th>
<th data-column-id="MaterialCost" data-formatter="Price" data-sortable="false">Price</th>
<th data-column-id="RowNumber" data-formatter="Amount" data-sortable="false">Amount</th>
</tr>
</thead>
</table>
</div>

Dompdf LoadView variable passing

i can't load able to pass a parameter to the dompdf function LoadView.
this is my controller:
public function pst_affluiti(){
$data=DB::all('Anagrafica')->get();
$pdf = PDF::loadView('output',['data' => $data]);
return $pdf->stream('output.pdf');
}
my output.blade.php
<body>
<div class="container">
<table class="table table-sm table-bordered" >
<thead>
<tr>
<th scope="col-sm-1 col-6">Data Affl.</th>
<th scope="col-sm-2">Cron.</th>
<th scope="col-sm-2">Cognome</th>
<th scope="col-sm-2">Nome</th>
<th scope="col-sm-2">Data nac.</th>
</tr>
</thead>
<tbody>
#foreach($data as $row)
<tr>
<td>{{$row->Cron}}</td>
<td>{{$row->Surname}}</td>
<td>{{$row->Name}}</td>
<td>{{$row->Date}}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</body>
if i load a normal view of my query it works well.
Any suggest?
Thanks in advance
you can use
compact('data')
instead of
$data

Resources