如何解决刀片文件中的Laravel7使用功能
我正在使用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>
解决方法
<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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。