gpt4 book ai didi

php - 数据库 | PHP |错误?

转载 作者:太空宇宙 更新时间:2023-11-03 11:46:47 26 4
gpt4 key购买 nike

我想显示每一季的插曲。我在第一次查询时使用了“echo”并显示了“[]”。问题是什么?请帮忙:D

ErrorException in 0405298c171379ebd6bef291f52165f99119355b.php line 47: Object of class Illuminate\Database\Eloquent\Collection could not be converted to int (View: C:\xamppp\htdocs\filmeseriale\resources\views\admin\seriale\show.blade.php) QUERY

    $sezon_episod2 = sezon_serial::select()->where('nume_serial','=',$seriale->id)->get();

$episoade = Episod::where('id_serial','=',$seriale->id)->where('id_sezon','=',$sezon_episod2)->get();

Html-显示 View

        @foreach($sezon_episod as $sezon)
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">

<a data-toggle="collapse" href="#collapse{{ $sezon->numar_sezon }}">Sezon: {{ $sezon->id }}</a>


</h4>
</div>
<div id="collapse{{ $sezon->numar_sezon }}" class="panel-collapse collapse">
<ul class="list-group">

@if($sezon->id == $sezon_episod2)

@foreach($episoade as $episod)

<li class="list-group-item">

Episodul: {{ $episod->nume_episod }}


</li>

@endforeach
@endif

</ul>

</div>

</div>

</div>
@endforeach
</div>

最佳答案

您的第一个查询返回一个集合,然后您像使用整数一样使用这个集合。尝试使用 first() 而不是 get(),这将返回单个 sezon_serial 对象,因此您不应再获取集合。

$sezon_episod2 = sezon_serial::select('id')->where('nume_serial','=',$seriale->id)->first();

关于php - 数据库 | PHP |错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38145272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com