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>
Related
I ask if anyone can help me, I import an excel table and create several rows of data with a column with the same reference, I want to update a field with a single input of all the rows with the 'Same' reference, for example I want to change the value of the same column with a single input and update the data to all, or add if it does not exist
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Same</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>255</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>255</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>255</td>
</tr>
</tbody>
</table>
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();
}
I have written html in shell script and saving that output to output.html and i want convert that output.html to output.pdf and to output.json how to do that?
<table class="table table-sm">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>#mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>#fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td colspan="2">Larry the Bird</td>
<td>#twitter</td>
</tr>
</tbody>
</table>
to convert the file in PDF you may need the utility to be installed
Follow this link to get this done
once you install the same, using the link mentioned run this
html2pdf filename
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
I have an array of data to display using table in html .but the foreach loop which i m using is not giving the desired format .
Below is the array data
$data = Array
(
[0] => Array
(
[id] => 10
[asset_name] => Mini Paver
[qty] => 3
[est_start_date] => 02/05/2017
[days] => 2
[comments] => Comment 2
[bundle_name] => 1XRoller 1XPaver
)
[1] => Array
(
[id] => 11
[asset_name] => Roller
[qty] => 2
[est_start_date] => 03/07/2018
[days] => 4
[comments] => Comment 2
[bundle_name] => 1XRoller 1XPaver
)
)
my view html code :
#foreach($data as $value)
<table class="" style="width: 100%;border:1px solid #ccc">
<thead>
<tr>
<th colspan="4"> <p><?php echo $value['bundle_name'];?> </p></th>
</tr>
<tr>
<th style="text-align: center">id</th>
<th style="width:5%;text-align: center">Asset Category</th>
<th style="width:5%;text-align: center">Days</th>
<th style="width:5%;text-align: center">Qty</th>
</tr>
</thead>
<tbody>
<tr>
<th style="text-align: center"><?php echo $value['id'];?> </th>
<th style="width:5%;text-align: center"><?php echo $value['asset_name'];?></th>
<th style="width:5%;text-align: center"><?php echo $value['days'];?></th>
<th style="width:5%;text-align: center"><?php echo $value['qty'];?></th>
</tr>
</tbody>
</table>
#endforeach
By using above for each loop i m getting the below html format like bundle name is repeating .
But i need the output should be like as below :
that means i want the bundle name shluld come only one time and the rest of details should display as in rows .
How do i do that ? any suggestions please ?
Thank you .
Please try the below code,
I have assumed the below points,
1. Your bundle_name will change(that is you will have various bundle_name). This code will work even if you have single bundle_name.
2. You will sort the result by bundle_name.
3. You need bundle title & table header for each bundle_name(again, this code will work even if you have single bundle_name).
4. bundle_name will never have a value false.
#php ($bundle_name = false)
#foreach($data as $value)
#if($bundle_name != $value['bundle_name'])
#if($bundle_name != false)
</tbody>
</table>
#endif
#php ($bundle_name = $value['bundle_name'])
<table class="" style="width: 100%;border:1px solid #ccc">
<thead>
<tr>
<th colspan="4"> <p> {{ $bundle_name }} </p></th>
</tr>
<tr>
<th style="text-align: center">id</th>
<th style="width:5%;text-align: center">Asset Category</th>
<th style="width:5%;text-align: center">Days</th>
<th style="width:5%;text-align: center">Qty</th>
</tr>
</thead>
<tbody>
#endif
<tr>
<th style="text-align: center">{{ $value['id'] }} </th>
<th style="width:5%;text-align: center">{{ $value['asset_name'] }}</th>
<th style="width:5%;text-align: center">{{ $value['days'] }}</th>
<th style="width:5%;text-align: center">{{ $value['qty'] }}</th>
</tr>
#endforeach
</tbody>
</table>