我正在使用Laravel 7,并且有一个视图文件,我在视图文件的顶部放置了一个函数。 但是,现在页面上出现错误。我基本上只是在尝试创建一个查询网址数据库的页面,然后使用curl函数查看该网站是否可用。
syntax error, unexpected 'endforeach' (T_ENDFOREACH)
(View: /Applications/MAMP/htdocs/local-devcenter/resources/views/uptime-dashboard.blade.php)
这是我的刀片文件代码
<?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>
答案 0 :(得分:1)
<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>