首页 > 解决方案 > 使用 laravel 在代码中间结束一个 for 循环

问题描述

我的页面如下所示:

    @foreach
//create a div here
//and the div needs to use the outside function like
<input value="{{ showText }}"> // there is a form as well
// and the foreach ends.
@endforeach

<?php
//and the function is here.
function showText(){
//connect to database
//get the required information
//return the information
}

现在,该showText()函数返回一个 id,它用于更新数据库中的信息。但是,由于@foreach, showText() 函数不返回任何内容,并且 Laravel 显示 id 不能为 null 或类似的错误。当我前段时间使用 PHP 做同样的事情时,我可以这样做:

<?php
for(){
?>
<div> Get the data through AJAX </div>
<?php
}

那么,我如何使用 laravel 做同样的事情呢?

标签: phplaravelforeach

解决方案


推荐阅读