【发布时间】:2020-01-10 14:21:57
【问题描述】:
我有这个问题,我需要通过数据透视表中的 id 获得模式的初始值,但它会返回给我:
stdClass 类的对象无法转换为字符串
这是我的控制器
$filiere = Filiere::all();
$fcount = count($filiere);
$filiere22 = DB::select('select id from filiere');
foreach ($filiere22 as $filiere2 ){
$md = DB::select('select intitule from mode_formation where id in(SELECT mode_id from mode_filiere where filiere_id='.$filiere2.')');
} return view('pgsec',compact('md','ssec','s_secteur','filiere','secteur','sec','secteur2','niveau','niv','province','pr','fcount','region','r','op','operateur'));
这是我的刀片
@foreach($filiere as $f)
<tr class="item{{$f->id}}">
<td style="font-size: 13px;">
<a href="f/{{$f->id}}">{{$f->intitule}}</a>
</td>
@foreach($md as $m)
<td style="font-size: 13px;">{{$m->intitule}}</td>
@endforeach
</tr>
@endforeach
【问题讨论】:
-
映射
filiere、mode_formation和mode_filiere tables的模型是什么?此外,这些表中的每一个的外键和引用都会很有用。可以发一下吗? -
您可以通过使用 Eloquent 关系以非常简单的方式做到这一点。我想这就是@IGP 询问模型的原因。
-
是的,谢谢,filiere 表有 id , intitule , mode_formation 有 , id 和 intitule 和 mode_filiere 表有 : filiere_id , mode_id
标签: php laravel pivot pivot-table laravel-blade