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..
Related
I am working with DOMPDF in Laravel 8, when I create a table with many records and jumps to the next page, it does not perform the page break as it should, Could someone help me to know what I am doing wrong?. I was reading many articles on the internet and none of them worked for me.
Here is my code:
<div class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
#for($i = 0; $i < 100; $i++)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
#endfor
</tbody>
</table>
</div>
Result:
Go to screenshot (https://ibb.co/Rj5ZPTW)
.page_break {
page-break-before: always;
}
<!-- adjust $n as needed. $n = number of rows that fit in a page -->
#foreach(collect(range(1,100))->chunk($n) as $chunk)
<div class="box-products-table">
<table class="table table-striped table-bordered">
<tbody>
<tr>
<td class="text-center roboto">{{ trans('image') }}</td>
<td class="text-center roboto">{{ trans('just_name') }}</td>
<td class="text-center roboto">{{ trans('quantity') }}</td>
<td class="text-center roboto">{{ trans('unit_price') }}</td>
<td class="text-center roboto">{{ trans('taxes') }}</td>
<td class="text-center roboto">{{ trans('subtotal') }}</td>
<td class="text-center roboto">{{ trans('total_price') }}</td>
</tr>
#foreach($chunk as $i)
<tr>
<td class="text-center"><img src="{{ public_path('storage/uploads/products/d6d74f351d482bb41787e86350ace02e.jpg') }}" height="70px"></td>
<td class="text-center">PORTATIL DELL 4HWRT</td>
<td class="text-right">526</td>
<td class="text-right">$ 4.985.650</td>
<td class="text-right">$ 947.273,5</td>
<td class="text-right">$ 99.713.000</td>
<td class="text-right">$ 2.622.451.900</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<div class="page-break"></div> <!-- break page -->
#endforeach
I am developing a website in laravel.
I am using =>
Laravel version: 5.7
Xampp version: xampp-win32-7.2.8-0-VC15-installer.exe
Bootstrap version: 4.1.3
jquery version: 3.3.1
PHP version: 7.2.8
When refreshing website some rows skipped. Sometimes it is works correctly, but sometimes skipped some rows and HTML tags were broken.
For example:
blade.php:
<div class="col-lg-4 col-sm-6 mt-3">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Title</th>
<th>Time</th>
<th>Count</th>
</tr>
</thead>
<tbody>
#forelse($bestPosts as $bestPost)
<tr>
<td>{{ $bestPost->title }}</td>
<td>{{ date('d.m.Y', strtotime($bestPost->datetime)) }}</td>
<td>{{ $bestPost->hits }}</td>
</tr>
#empty
<tr>
<td colspan="3" class="text-center bg-warning">No post</td>
</tr>
#endforelse
</tbody>
</table>
</div>
<div class="col-lg-4 col-sm-6 mt-3">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Country</th>
<th>Year</th>
<th>Month</th>
<th>Count</th>
</tr>
</thead>
<tbody>
#forelse($newVisitors as $newVisitor)
<tr>
<td>
<img src="/flags/{{ $newVisitor->country_code3 }}.png" alt="{{ $newVisitor->country_code3 }}" class="border mr-1">
{{ $newVisitor->country_code3 }}
</td>
<td>{{ $newVisitor->year }}</td>
<td>{{ $newVisitor->month }}</td>
<td>{{ $newVisitor->count }}</td>
</tr>
#empty
<tr>
<td colspan="4" class="text-center bg-warning">No visitor</td>
</tr>
#endforelse
</tbody>
</table>
</div>
output HTML :
Ho can I solve this problem
Sometimes when refresh red lines are skipped
You are missing a < at row
img src="/flags/{{ $newVisitor->country_code3 }}.png" alt="{{ $newVisitor->country_code3 }}" class="border mr-1">
try this code :
<div class="col-lg-4 col-sm-6 mt-3">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Title</th>
<th>Time</th>
<th>Count</th>
</tr>
</thead>
<tbody>
#if(count($bestPosts)>0)
#foreach($bestPosts as $bestPost)
<tr>
<td>{{ $bestPost->title }}</td>
<td>{{ date('d.m.Y', strtotime($bestPost->datetime)) }}</td>
<td>{{ $bestPost->hits }}</td>
</tr>
#endforeach
#else
<tr>
<td colspan="3" class="text-center bg-warning">No post</td>
</tr>
#endif
</tbody>
</table>
</div>
<div class="col-lg-4 col-sm-6 mt-3">
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Country</th>
<th>Year</th>
<th>Month</th>
<th>Count</th>
</tr>
</thead>
<tbody>
#if(count($newVisitors)>0)
#foreach($newVisitors as $newVisitor)
<tr>
<td>
<img src="{{ '/flags/'.$newVisitor->country_code3 }}.png" alt="{{ $newVisitor->country_code3 }}" class="border mr-1" />
{{ $newVisitor->country_code3 }}
</td>
<td>{{ $newVisitor->year }}</td>
<td>{{ $newVisitor->month }}</td>
<td>{{ $newVisitor->count }}</td>
</tr>
#endforeach
#else
<tr>
<td colspan="4" class="text-center bg-warning">No visitor</td>
</tr>
#endif
</tbody>
</table>
</div>
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>
Button doesnot work after using form inside #foreach. Any suggestion about how to use form inside a #foreach loop ?
is it even possible to use form inside a loop in laravel blade file?
here is my code of my laravel blade file. I have used form inside foreach for getting data of Book Amount. Any Suggestion about how to solve this problem?
#extends('layouts.app')
#section('content')
<div class="container">
<h1>Items On Cart:</h4>
<div class="row justify-content-center">
<div class="col-md-12">
<div class="card">
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
#foreach($cart_items as $data)
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<tr>
<th>{{ show_books_name($data->book_id) }}</th>
<th>{{ show_books_author($data->book_id) }}</th>
<th><input type="number" name="amount" id="amount" value="{{ $data->item_amount }}"></th>
<th>{{ $data->price }} tk</th>
<th><button type="submit" class="btn btn-success">Change</button></th>
<th><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></th>
</form>
#endforeach
</table>
</div>
<h2 style="padding-left:865px">Total = {{ $cart_info->total_price }} tk</h2>
</div>
</form>
</div>
</div>
</div>
#endsection
The simplest solution can be: place a form tag into a td, (btw it should be td, not th, you use th in thead):
<table style="border-collapse: collapse;width: 100%;">
<tr style="border: 1px solid #dddddd;text-align: left;padding: 8px;font-size:20px;color: gray">
<th>Book Name</th>
<th>Author Name</th>
<th>Book Amount</th>
<th>Price</th>
<th>Action</th>
<th>Action</th>
</tr>
#foreach($cart_items as $data)
<tr>
<td>{{ show_books_name($data->book_id) }}</td>
<td>{{ show_books_author($data->book_id) }}</td>
<td> <!-- Here we have empty td now --> </td>
<td>{{ $data->price }} tk</td>
<td>
<!-- Form is here now -->
<form action="{{ route('change_item_amount',[$cart_info->id,$data->book_id]) }}" method="POST">
<input type="number" name="amount" id="amount" value="{{ $data->item_amount }}">
<button type="submit" class="btn btn-success">Change</button>
</form>
</td>
<td><a class="btn btn-success" href="{{ route('delete_book',[$cart_info->id,$data->book_id] ) }}">Delete</a></td>
#endforeach
</table>
I've got this code:
<div class="container col-md-6 col-md-offset-3">
<div class="well well bs-component">
<table class="table">
<thead>
<tr>
<th>Logo</th>
<th>Bedrijfsnaam</th>
<th>Plaats</th>
</tr>
</thead>
<tbody>
#foreach($companies as $company)
<a href="/bedrijf/{!! $company->CompanyId !!}">
<tr>
<td><img class="img-circle-company" src="{!! $company->Logo != null ? '/files/images/companylogos/'.$company->Logo : '/files/images/companylogos/default.png'!!}"/></td>
<td>{{ $company->CompanyName }}</td>
<td>{{ $company->City }}</td>
</tr>
</a>
#endforeach
</tbody>
</table>
</div>
But the a tag is not working why is that? In my page source it looks like this:
Unfortunately wrapping <tr> elements in an anchor isn't valid HTML. Some browsers may not blink an eye at it, but most with remove the offending element. If you want to continue using tables, another option would be to add the anchor inside each <td> element.
<div class="container col-md-6 col-md-offset-3">
<div class="well well bs-component">
<table class="table">
<thead>
<tr>
<th>Logo</th>
<th>Bedrijfsnaam</th>
<th>Plaats</th>
</tr>
</thead>
<tbody>
#foreach($companies as $company)
<tr>
<td>
<a href="/bedrijf/{!! $company->CompanyId !!}">
<img class="img-circle-company" src="{!! $company->Logo != null ? '/files/images/companylogos/'.$company->Logo : '/files/images/companylogos/default.png'!!}"/>
</a>
</td>
<td><a href="/bedrijf/{!! $company->CompanyId !!}">{{ $company->CompanyName }}</td>
<td>{{ $company->City }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>