0

I want to display episode of every season. i used "echo" at first query and has displayed "[]".What is the problems ? Please help :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();

The Html- show 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>
0

3 Answers 3

2

Your first query returns a collection, and then your are using this collection like an integer. Try with first() instead of get(), this will return a single sezon_serial object, so you shouldn't get a collection anymore.

$sezon_episod2 = sezon_serial::select('id')->where('nume_serial','=',$seriale->id)->first();
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you- the next error after editing Object of class App\sezon_serial could not be converted to int (View: C:\xamppp\htdocs\filmeseriale\resources\views\admin\seriale\show.blade.php)
@AdrianCaragea In which line? Probably here: @if($sezon->id == $sezon_episod2). You are comparing an integer with an object. Try @if($sezon->id == $sezon_episod2->id)
1

I solved but i need all, not only first.

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

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

Show View

>  @if($sezon->id == $sezon_episod3->id)
>                                     @foreach($episoade as $episod)
>                                          <li class="list-group-item">
>                                              Episodul: {{ $episod->nume_episod }}
>                                         </li>
>                                     @endforeach
>                                 @endif

enter image description here

enter image description here

2 Comments

I suppose that you have a serials table, sezons table and episodes table and you want to show all the sezons and the episodes of each seazon for a specified serial. You only have to define the relationships between the models, and then it can be something like @foreach($serial->sezons as $sezon) $sezon->name @foreach($sezon->episodes as $episode) $episode->name @endforeach @endforeach. Of course, you have to use your own methods and properties names.
Take a look at this question if you aren't already acquainted with eloquent relationships, or directly at Laravel Docs.
0

Two different errors.

FIRST

ErrorException in 0405298c171379ebd6bef291f52165f99119355b.php line 49: Invalid argument supplied for foreach() (View: C:\xamppp\htdocs\filmeseriale\resources\views\admin\seriale\show.blade.php)

Query

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

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

SHOW BLADE

                    <ul class="list-group">
                        @if($sezon->id == $sezon_episod2->id)
                            @foreach($episoade as $episod)
                                 <li class="list-group-item">
                                     Episodul: {{ $episod->nume_episod }}
                                </li>
                            @endforeach
                        @endif
                    </ul>

And when i put "->get()" at "$episoade" i have this error,

ErrorException in 0405298c171379ebd6bef291f52165f99119355b.php line 72:

Trying to get property of non-object (View: C:\xamppp\htdocs\filmeseriale\resources\views\admin\seriale\show.blade.php)

1 Comment

First error: With first() you only have a single object, not a collection, so you can't iterate over a foreach. Second error: You are trying to get a property from a variable who is not an object, maybe it is a collection, or a null object if the query can't find any match on the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.