如何显示模型的第n个子代?

时间:2019-09-02 07:43:04

标签: html laravel laravel-blade

如何在页面上正确显示模型?我有一个这样的模型Process,一个 hasOne Person和一个人 hasMany Training,所以在我的ProcessController@show这个:

$process = Process::where('id', $process->id)->with(['person'])->firstOrFail();
dd($process->person->trainings);

在该模具上转储并输出属于该特定人员的所有培训数据,但是我的问题在此页面上(我的流程show.blade.php),它没有显示我的数据:

<table class="table4 display compact">
    <tr style="line-height: 5px;">
        <th style="display: none;">Id</th>
        <th>Training</th>
        <th>Description</th>
        <th width="30px;"></th>
    </tr>
    @if ($process->person && count($process->person->trainings) > 0)
    @foreach ($process->person->trainings as $training)
    <tr class="hide" style="line-height: 5px;">
        <td style="display: none;">{{ $training->id }}</td>
        <td contenteditable="false">{{ $training->training_name }}</td>
        <td contenteditable="false">{{ $training->description }}</td>
        <td>
            <!--span class="table-remove4 glyphicon glyphicon-remove"><i class="fas fa-minus-circle"></i></span-->
        </td>
    </tr>
    @endforeach
    @else
    <tr class="hide" style="line-height: 10px;">
        <td style="display: none;"></td>
        <td contenteditable="true"></td>
        <td contenteditable="true"></td>
        <td>
            <span class="table-remove4 glyphicon glyphicon-remove"><i class="fas fa-minus-circle"></i></span>
        </td>
    </tr>
    @endif
</table>

0 个答案:

没有答案