I have a problem to print rowspan inside a foreach loop. I want the result to look like this,
Result that I expected (code with HTML)
I write my code in php file called,
project-detail.blade.php
<?php $no = 1; ?>
#foreach($tasks as $task)
<tr>
<td rowspan="{{ count($tasks) }}">{{ $no }}</td>
<td rowspan="{{ count($tasks) }}">{{ $task->name }}</td>
<td onclick="getTaskDescription('{{$task->task_id}}')">
{{ $task->task_detail }}(Click for description)
</td>
<td>83%</td>
<td>Not yet</td>
<td rowspan="{{ count($tasks) }}">
<button class="btn btn-info btn-sm" style="border-radius: 0"><i class="icon icon-plus" style="font-size: 12px">
</i> Add Task</button>
</td>
</tr>
<tr>
<td>Second task (Click for description)</td>
<td>50%</td>
<td><button class="btn btn-default btn-sm">Review</button></td>
</tr>
<?php $no++; ?>
#endforeach
However, I am not getting expected result. Result of my code looks like this,
Result link
Can anyone help me? Thanks.
I think your code show correct view. Give some bottom padding on td . Hope you will be get your excepted view.
Related
I am working on the below code, where the same question can have multiple images as an answer.
So, they are displaying properly but, with every image, the same question is repeating multiple times.
So, I want the question to display only once and below that the answers should be displayed. Below is the code. I have created a table and the images will be displayed after the question. Same has been highlighted below. I have done some POC, please have a look.
<!--Question and Answer Section Open-->
#if($submited_documents->count() !=0)
<table class="table table-bordered">
<tbody>
#if(count($submited_documents) > 0)
#foreach($submited_documents as $documents)
<tr>
<th style="width:50% !important; border:1px solid lightgray;"><strong>Question{{$documents->sequence}} : </strong></th>
<th style="border:1px solid lightgray; "><strong>Answer : </strong></th>
</tr>
<tr>
<td>{{ $documents->question }}</td>
<td>{{ $documents->comments }}</td>
</tr>
#endforeach
#endif
</tbody>
</table>
<table>
<tbody>
#foreach($submited_documents as $documents)
<tr>
<td style="border-radius: 2px;">
<strong>Question{{$documents->sequence}} : </strong>{{ $documents->question }}
</td>
</tr>
#if(count($documents->pictures) > 0 )
#foreach($documents->pictures as $document_picture)
<tr>
<td class="td_class">
#if($document_picture->filename != null)
<a style="" href="{{ URL::to('public/uploads/pickups/'.$document_picture->filename) }}" target="new">
<img src="{{ URL::to('public/uploads/pickups/'.$document_picture->filename) }}"
alt="{{ $document_picture->filename }}" title="{{ $document_picture->filename }}"
style="width: 50% !important;height: 50% !important;" ></a><br>
#endif
</td>
</tr>
#endforeach
#endif
#endforeach
</tbody>
</table>
#endif
<!--Question and Answer Section End-->
Any help is appreciated..
I have the following loop where I extract values from a query and write a table with it, in the field for the age I need to change the 's class based on the value of the days passed since the date of shipment and today
I already tried with in CSS like[data-age >180] but I only get errors, and I can't find a case similar to my needs, additionally id like to do it inside the loop instead of an additional piece of code, because it messes up my view
#foreach($shipments as $shipment)
<tr>
<td data-title="id">{{$shipment->id}}</td>
<td class=tracking data-title="tracking">{{$shipment->tracking}}</td>
<td data-title="PartNumber">{{$shipment->PartNumber}}</td>
<td data-title="DateShipped">{{$shipment->DateShipped}}</td>
<td
data-title="age"
data-age="{{
(int) floor(
(time() - strtotime($shipment->DateShipped))
/ (60 * 60 * 24)
)
}}"
>{{
(int) floor(
(time() - strtotime($shipment->DateShipped)) / (60 * 60 * 24)
)
}} days
</td>
<td data-title="Qtyorder">{{$shipment->Qtyorder}}</td>
<td data-title="QtyShipped">{{$shipment->QtyShipped}}</td>
<td data-title="QtyBckorder">{{$shipment->QtyBckorder}}</td>
<td data-title="purchaseOrder">{{$shipment->purchaseOrder}}</td>
<td data-title="OrderNumber">{{$shipment->OrderNumber}}</td>
<td data-title="paperwork">{{$shipment->paperwork}}</td>
<td data-title="VMIreceived">{{$shipment->VMIreceived}}</td>
<td data-title="VMIticketNumber">{{$shipment->VMIticketNumber}}</td>
<td data-title="VMILRB">{{$shipment->VMILRB}}</td>
<td>
<a
href="{{ route('shipment.edit',$shipment->id)}}"
class="btn btn-primary"
>
Edit
</a>
</td>
<td>
<form action="{{ route('shipment.destroy', $shipment->id)}}" method="post">
#csrf
#method('DELETE')
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
#endforeach
try a one line if statement
{{ $condition ? value if true : value if false }}
Untested, but can you please try this:
#foreach($shipments as $shipment)
#php
$time_passed = $shipment->DateShipped->diffInSeconds(now());
#endphp
<tr>
<td class="{{ time_passed > some_number ? 'class_value_if_true' : 'class_value_if_false' }}">
{{ $time_passed }}
</td>
</tr>
#endforeach
I have a code:
<table class="table table-bordered">
<tr>
<td class="align-middle">
</td>
#forelse($products as $product)
<td>
<div class="comparison-item">
<a class="comparison-item-thumb" href="shop-single.html">
<img src="{{ Voyager::image($product->image) }}" alt="Apple iPhone X">
</a>
<a class="comparison-item-title" href="shop-single.html">{{ $product->title }}</a>
</div>
</td>
#empty
Нет товаров для сравнения
#endforelse
</tr>
#foreach($products as $keyp => $product)
#foreach($product->prodChar as $key => $char)
<tr>
<th>{{ $char->prodCharacter->title }}</th>
<td>{{ $char->value }}</td>
<td>-</td>
<td>-</td>
</tr>
#endforeach
#endforeach
<tr>
<th></th>
<td><a class="btn btn-outline-primary btn-sm btn-block" href="#" data-toast data-toast-type="success" data-toast-position="topRight" data-toast-icon="icon-check-circle" data-toast-title="Product" data-toast-message="successfuly added to cart!">Add to Cart</a></td>
<td><a class="btn btn-outline-primary btn-sm btn-block" href="#" data-toast data-toast-type="success" data-toast-position="topRight" data-toast-icon="icon-check-circle" data-toast-title="Product" data-toast-message="successfuly added to cart!">Add to Cart</a></td>
<td><a class="btn btn-outline-primary btn-sm btn-block" href="#" data-toast data-toast-type="success" data-toast-position="topRight" data-toast-icon="icon-check-circle" data-toast-title="Product" data-toast-message="successfuly added to cart!">Add to Cart</a></td>
</tr>
</table>
Image how this show:
I need write: "-". For product where attribute is none. Now I show all attributes in one column for every product. How I can fix this problem? I need compare keys of arrays?
If I understand correctly, you're talking about this small section here:
#foreach($product->prodChar as $key => $char)
<tr>
<th>{{ $char->prodCharacter->title }}</th>
<td>{{ $char->value }}</td>
<td>-</td>
<td>-</td>
</tr>
#endforeach
So you have two options here:
Option #1: You could compare right in the view as follows:
<td>{{ $char->value?: "-" }}</td>
This would return a - whenever your value is null.
Option #2: You could create a mutator within the ProductChar model as follows:
// ...your product model code
public function getValueAttribute() {
return $this->attributes['value']?: "-";
}
This would make it so that when you call $char->value it will use the value (if not null) or return a - if it is null.
So I have this forelse that displays all the variants, now what I want to happen is that, if there is no variant. the submit button will be disabled.
<table class="table table-striped">
<thead>
<tr>
<th class="col-sm-5">Name</th>
<th class="col-sm-1">Default?</th>
<th class="col-sm-2 text-right">Retail Price</th>
<th class="col-sm-2 text-right">Quantity</th>
<th class="col-sm-2"></th>
</tr>
</thead>
<tbody>
#forelse ($product->variants as $index => $variant)
<tr>
<td>{{ $variant->name }}</td>
<td>{{ $variant->is_default ? 'Yes' : 'No' }}</td>
<td class="text-right">{{ number_format($variant->retail_price, 2) }} {{ $variant->price_currency }}</td>
<td class="text-right">{{ number_format($variant->quantity, 0) }}</td>
<td>Edit</td>
</tr>
#empty
<tr>
<td colspan="5">No variants found</td>
<?php $varbutton = 'disabled';?>
</tr>
#endforelse
</tbody>
</table>
here is the button
<div class="panel-footer">
<button class="btn btn-default" type="submit"<?php $varbutton; ?>>Update Store</button>
</div>
Is it possible using php and html in the blade alone or do I have to do it in the controller?
You should be using blade in your button:
<div class="panel-footer">
<button class="btn btn-default" type="submit" {{ $varbutton }}>Update Store</button>
</div>
Also please note that there needs to be a space after "submit".
Or, if you don't want that space when the button is not disabled, use:
<?php $varbutton = ' disabled';?>
<div class="panel-footer">
<button class="btn btn-default" type="submit"{{ $varbutton }}>Update Store</button>
</div>
here I would like to make a table where there number of rows will automatically be made in accordance with the data in $ kosts-> stock_room. and then there is also I want to make the data directly arranged with the data I have on the table residents by room number, so if i have data in table 'residents' with room number 10 its will fill the table with row 10.
here my code :
<table class="table table-hover table-striped">
<tr>
<th width="10%">Action</th>
<th>Room</th>
<th>Kost</th>
<th>Name</th>
<th>Due Date</th>
</tr>
<tr>
#foreach($posts as $row)
#for($i=1;$i<=$kosts->stock_room;$i++)
<tr>
<td>
<a title='Edit Data' class='btn btn-xs btn-warning' href='{{ url("resident/edit/$i") }}'><i class='fa fa-pencil'></i></a>
<a title='Delete Data' class='btn btn-xs btn-danger' href='{{ url("resident/delete/$i") }}' onclick="return confirm('sure to delete ?')"><i class='fa fa-trash'></i></a>
</td>
<td>{{$i}}</td>
<td></td>
<td>{{$row->name}}</td>
<td></td>
</tr>
#endfor
#endforeach
</tr>
</table>
have someone can help me, to make my code can work exactly like I want?
my wrong result now :
in there my data its always looping
its should be like this : (in there i only make 10 row)
data in my table :
for example in there i have data with room number 9 so my table with number 9 its fill with data from database with room number 9
and iam sorry for my bad english
Try this:
#foreach($posts as $row)
#for($i=1;$i<=$kosts->stock_room;$i++)
<tr>
..... // Put <tr> inside loop so that it can generate a new table row for each iteration
</tr>
#endfor
#endforeach
i think you have added your tr in wrong location as have not shown any desired structure as a assumption i have made a correction please try with this code :
<table class="table table-hover table-striped">
<tr>
<th width="10%">Action</th>
<th>Room</th>
<th>Kost</th>
<th>Name</th>
<th>Due Date</th>
</tr>
#foreach($posts as $row)
<tr>
#for($i=1;$i<=$kosts->stock_room;$i++)
<td>
<a title='Edit Data' class='btn btn-xs btn-warning' href='{{ url("resident/edit/$i") }}'><i class='fa fa-pencil'></i></a>
<a title='Delete Data' class='btn btn-xs btn-danger' href='{{ url("resident/delete/$i") }}' onclick="return confirm('sure to delete ?')"><i class='fa fa-trash'></i></a>
</td>
<td>{{$i}}</td>
<td></td>
<td>{{$row->name}}</td>
<td></td>
#endfor
</tr>
#endforeach
</table>
if its not help then please put the dump of your arrays and desired structure you want to display