如何在刀片服务器的foreach循环中插入表行。在laravel 5.2中的php文件?

时间:2022-10-26 09:16:45

I have created a view page where I am getting an Eloquent variable from my controller. That variable points to the elements in a table. This is my current code.

我创建了一个视图页面,在这个页面中,我从我的控制器获得了一个有说服力的变量。该变量指向表中的元素。这是我当前的代码。

  <table border="0px">
    <tr>
    @foreach ($teacher as $value) 
        <?php    
            $tid = $value->teacherID;
        ?>

        <tr>
            <td> <a href="info/{{ $tid }}"> {{ $value['teacher_name'] }} </a></td>
            <td>{{ $value['course_name'] }}</td>
        </tr>
        <hr>

    @endforeach
    </tr>
</table>

I am getting an unexpected output with this code. I am getting number of blank spaces in the beginning and then my table(mysql) elements. Please help me resolve the issue guys. Thanks, Regards.

我用这段代码得到一个意想不到的输出。我在开始时得到了空格,然后是表(mysql)元素。请帮我解决这个问题。谢谢,问候。

2 个解决方案

#1


1  

Laarvel follow this approach:

Laarvel遵循这种方法:

Controller function:

控制器功能:

myFunction()
{
    $myData = array('1' => 'One', '2' => 'Two');    // sample data. You can get this data from DB
    return view('myView', array('data' => $myData));
}

myView.blade.php:

myView.blade.php:

Here you can use the $data array like:

这里可以使用$data数组:

{{ $data['1'] }}
{{ $data['2'] }}

Now track your methods accordingly.

现在根据您的方法进行跟踪。

#2


0  

public function getTeachers(){
    $teachers = Teachers::all();
    return('teachers',compact('teachers'));
}

in blade file you can read properties in

在blade文件中,可以在其中读取属性

 @foreach ($teacher as $value) 
    if($value != '' || $value != null)
        ID:{{$value->teacherID}}
 @endforeach

#1


1  

Laarvel follow this approach:

Laarvel遵循这种方法:

Controller function:

控制器功能:

myFunction()
{
    $myData = array('1' => 'One', '2' => 'Two');    // sample data. You can get this data from DB
    return view('myView', array('data' => $myData));
}

myView.blade.php:

myView.blade.php:

Here you can use the $data array like:

这里可以使用$data数组:

{{ $data['1'] }}
{{ $data['2'] }}

Now track your methods accordingly.

现在根据您的方法进行跟踪。

#2


0  

public function getTeachers(){
    $teachers = Teachers::all();
    return('teachers',compact('teachers'));
}

in blade file you can read properties in

在blade文件中,可以在其中读取属性

 @foreach ($teacher as $value) 
    if($value != '' || $value != null)
        ID:{{$value->teacherID}}
 @endforeach