I am using Laravel 7 and have a view file that I put a function in the top of the view file.
However I am getting an error now on the page. I am basically just trying to create a page that queries a database of urls and then uses a curl function to see if the website is available or not.
syntax error, unexpected 'endforeach' (T_ENDFOREACH)
(View: /Applications/MAMP/htdocs/local-devcenter/resources/views/uptime-dashboard.blade.php)
Here is my code for the blade file
<?php
//stuck function here becauae needed it only in this template
function uptime_monitor($url)
{
$timeout = 10;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, $timeout);
$http_respond = curl_exec($ch);
$http_respond = trim(strip_tags($http_respond));
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (($http_code == "200") || ($http_code == "302")) {
return true;
} else {
// return $http_code;, possible too
return false;
}
curl_close($ch);
}
?>
<table class="table-auto rounded text-center" id="sitegridtable">
<thead>
<!--<tr>
<th class="border w-1/4 px-4 py-2">Site URL</th>
<th class="border w-1/6 px-4 py-2">HTTPS</th>
<th class="border w-1/6 px-4 py-2">HTTP</th>
<th class="border w-1/6 px-4 py-2">Last updated On</th>
<th class="border w-1/6 px-4 py-2">Actions</th>
</tr>-->
</thead>
<tbody>
#foreach($clientdomains as $clientdomain)
<tr>
<td> {{$clientdomain->websiteurl}}</td>
#if(#uptime_monitor('http://'.$clientdomain->websiteurl))
<td>Up</td>
#else
<td>Down</td>
<td></td>
<td> </td>
<td>
</td>
</tr>
#endforeach
</tbody>
</table>
<table class="table-auto rounded text-center" id="sitegridtable">
<thead>
<!--<tr>
<th class="border w-1/4 px-4 py-2">Site URL</th>
<th class="border w-1/6 px-4 py-2">HTTPS</th>
<th class="border w-1/6 px-4 py-2">HTTP</th>
<th class="border w-1/6 px-4 py-2">Last updated On</th>
<th class="border w-1/6 px-4 py-2">Actions</th>
</tr>-->
</thead>
<tbody>
#foreach($clientdomains as $clientdomain)
<tr>
<td> {{$clientdomain->websiteurl}}</td>
#if(#uptime_monitor('http://'.$clientdomain->websiteurl))
<td>Up</td>
#else
<td>Down</td>
#endif
<td></td>
<td> </td>
<td>
</td>
</tr>
#endforeach
</tbody>
</table>
Related
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**
everything works perfectly but it throw an error “Trying to get
property ‘path’ of non-object” on this line
“unlink(“uploads/”.$img->path);” and when I refresh the row and file
are deleted .if there is another way please tell me
blade :
<table class="table table-hover">
<thead>
<tr>
<th scope="col">image</th>
<th scope="col">title</th>
<th scope="col">Actions </th>
</tr>
</thead>
<tbody>
#foreach($data as $img)
<tr>
<th scope="row"> <img src="uploads/{{ $img->path }}" width="50%" /></th>
<td>{{$img->title}}</td>
<td>
<a href='#'><i class="fa fa-edit" id="updateIcon" wire:click="selectItem({{ $img->id }}, 'update')" ></i></a>
<i class="fa fa-trash" style='color:red;' wire:click="selectItem({{ $img->id }}, 'delete')" data-target="#modalFormDelete"></i>
</td>
#endforeach
</tr>
class:
public function selectItem($itemId, $action)
{
$this->selectedItem = $itemId;
if ($action == 'delete') {
$this->dispatchBrowserEvent('openDeleteModal');
}
}
public function delete()
{
$img=Caroussel_Img::find($this->selectedItem);
unlink("uploads/".$img->path);//bug here
Caroussel_Img::where("id",$img->id)->delete();
$this->dispatchBrowserEvent('closeDeleteModal');
}
It is not a good idea,
and I don't know what is inside "Caroussel_Img"
But if it is removing the file add "#" at beginning of the line and it won't bother you anymore
#unlink("uploads/".$img->path);
I'm using version Dompdf 0.8.5
This is my code and my PDF render:
<div>header</div>
<div>title</div>
<div>somethingelse</div>
<div class="detail" style="width:100%">
<table id="tbDetail" cellpadding="0" cellspacing="0" width="100%" style="font-size: 11.5px">
<thead>
<tr class="detail-header">
<td class="br-1 bb-1 bt-1 text-center" style="width:3%">NBR</td>
<td class="br-1 bb-1 bt-1 text-center" style="width:35%">Product</td>
<td class="br-1 bb-1 bt-1 text-center" style="width:13%">Unit</td>
<td class="br-1 bb-1 bt-1 text-center" style="width:10%">Quantity</td>
<td class="br-1 bb-1 bt-1 text-center" style="width:17%">Price</td>
<td class="br-1 bb-1 bt-1 text-center" style="width:19%">Total</td>
</tr>
</thead>
<tbody>
<xsl:for-each
select="(//node())[37 >= position()]">
<tr class="detail-data text-left">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
I am not sure why the desired row stating "No record found" is not displaying despite not having any data matching Selangor
BazaarLocController:
public function index()
{
$bzr = BzrLocation::where('area', 'Perlis')->get();
$bzr2 = BzrLocation::where('area', 'Selangor')->get();
$bzr3 = BzrLocation::where('area', 'Pahang')->get();
$bzr4 = BzrLocation::where('area', 'Johor')->get();
$bzr5 = BzrLocation::where('area', 'Melaka')->get();
$bzr6 = BzrLocation::where('area', 'Negeri Sembilan')->get();
$allbzr = [
'bzrloc' => $bzr,
'bzrloc2' => $bzr2,
'bzrloc3' => $bzr3,
'bzrloc4' => $bzr4,
'bzrloc5' => $bzr5,
'bzrloc6' => $bzr6
];
return view('admin.bazaarloc')->with($allbzr);
}
bazaarloc.blade.php:
<table class="table table-hover">
<caption>Table 2</caption>
<thead class="thead-dark">
<tr>
<th scope="col" style="width: 8%; vertical-align: top;">No.</th>
<th scope="col" style="width: 60%; vertical-align: top;">Location</th>
<th scope="col" style="width: 21%; vertical-align: top;">Amount Approved</th>
<th scope="col" style="width: 21%; vertical-align: top;">Description</th>
<th scope="col" style="width: 4%;"></th>
<th scope="col" style="width: 4%;"></th>
</tr>
</thead>
<tbody>
#php
$counting = 0
#endphp
#foreach($bzrloc2 as $bzr)
#php
$counting++
#endphp
<tr>
<th scope="row">{{$counting}}</th>
<td>{{$bzr->name}}</td>
<td>{{$bzr->totalPlot}}</td>
<td>{{$bzr->plotAvail}}</td>
<td><button type="submit" class="btn btn-success btn-sm">Edit</button></td>
<td>
<form method="POST" action="{{ route('bazaarLocation.destroy', $bzr->bzrloc_id) }}">
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Adakah anda pasti ingin membatalkan lokasi tersebut?')">Batal</button>
</form>
</td>
</tr>
#endforeach
#if(empty($bzrloc2))
<tr>
<td colspan="2">
No record found
</td>
</tr>
#endif
</tbody>
</table>
When printing out $bzrloc2, it displays []. Which confirms the array is empty. Based on the php manual, the empty() function should consider this empty and return true.
Because you use collection, not array. Collection will return false :
empty(collect([])) // false
empty([]) // true
Try following code :
<table class="table table-hover">
<caption>Table 2</caption>
<thead class="thead-dark">
<tr>
<th scope="col" style="width: 8%; vertical-align: top;">No.</th>
<th scope="col" style="width: 60%; vertical-align: top;">Location</th>
<th scope="col" style="width: 21%; vertical-align: top;">Amount Approved</th>
<th scope="col" style="width: 21%; vertical-align: top;">Description</th>
<th scope="col" style="width: 4%;"></th>
<th scope="col" style="width: 4%;"></th>
</tr>
</thead>
<tbody>
#if($bzrloc2->count())
#php
$counting = 0
#endphp
#foreach($bzrloc2 as $bzr)
#php
$counting++
#endphp
<tr>
<th scope="row">{{$counting}}</th>
<td>{{$bzr->name}}</td>
<td>{{$bzr->totalPlot}}</td>
<td>{{$bzr->plotAvail}}</td>
<td><button type="submit" class="btn btn-success btn-sm">Edit</button></td>
<td>
<form method="POST" action="{{ route('bazaarLocation.destroy', $bzr->bzrloc_id) }}">
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Adakah anda pasti ingin membatalkan lokasi tersebut?')">Batal</button>
</form>
</td>
</tr>
#endforeach
#else
<tr>
<td colspan="2">
No record found
</td>
</tr>
#endif
</tbody>
</table>
When you retrieve using ->get(), you should use count() function in order to check whether the Collection is empty or not.
Instead of using empty, try using count like:
#if($bzrloc2->count() < 1)
<tr>
<td colspan="2">
No record found
</td>
</tr>
#endif
please help me.
Trying to get property of non-object (View:
/Data/oa-dev4/resources/views/surat_tugas/list_surat_tugas/table_total.blade.php)
(View:
/Data/oa-dev4/resources/views/surat_tugas/list_surat_tugas/table_total.blade.php)
<div class="caption">
<i class="fa fa-table font-blue-oa"></i>
<span class="caption-subject font-blue-oa sbold uppercase">Rekap Biaya dan Pelaksanaan Surat Tugas Tahun {{$tahun_st}}</span>
</div>
<div class="portlet-body">
<table class="table table-datatable table-bordered table-checkable table-hover">
<thead>
<tr class="heading">
<th class='hidden'></th>
<th class="text-center"> </th>
<th class="text-center"> Jumlah Hari </th>
<th class="text-center"> Transport </th>
<th class="text-center"> Penginapan</th>
<th class="text-center"> Uang Harian</th>
<th class="text-center"> Jumlah</th>
</tr>
</thead>
<tbody>
<tr>
<td class='sbold'>Total</td>
#if($rekap->jumlah_hari)
<td class="text-right">{{$rekap->jumlah_hari}} Hari</td>
#else
<td class="text-right"> - </td>
#endif
#if(Helper::convert_rupiah($rekap->transport))
<td class="text-right">{{Helper::convert_number($rekap->transport)}}</td>
#else
<td class="text-right"> - </td>
#endif
#if(Helper::convert_rupiah($rekap->penginapan))
<td class="text-right">{{Helper::convert_number($rekap->penginapan)}}</td>
#else
<td class="text-right"> - </td>
#endif
#if(Helper::convert_rupiah($rekap->harian))
<td class="text-right">{{Helper::convert_number($rekap->harian)}}</td>
#else
<td class="text-right"> - </td>
#endif
#if(Helper::convert_rupiah($rekap->transport) || Helper::convert_rupiah($rekap->transport)|| Helper::convert_rupiah($rekap->transport))
<td class="text-right">{{Helper::convert_number($rekap->transport + $rekap->harian + $rekap->penginapan)}}</td>
#else
<td class="text-right"> - </td>
#endif
<tr>
</tbody>
</table>
</div>
The following error means you are accessing a value that is not an object.
Trying to get property of non-object
If the $rekap variable is an array then you have to convert it into an object and then access is in you blade template.