Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Call to undefined method stdClass::isEmpty() error

I am trying to check if the $pl1 is empty but it does not seems to work. I tried using count() but does not seems to work either.

controller:

$paperlist1 =   DB::table('upload_papers')
                        ->join('courselist','courselist.id', '=', 'upload_papers.courselist_id')
                        ->join('users','users.id','=','upload_papers.upload_by')
                        ->select('upload_papers.file_name','upload_papers.paper_no','upload_papers.path','users.role_id')
                        ->where([
                            ['courselist.faculty_id','=',$facultyid],
                            ['upload_papers.courselist_id','=',$id],
                            ['upload_papers.paper_no','=',1]
                            ])
                        ->get();

blade.php:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<tr>
@foreach($paperlist1 as $pl1)
                    @if(!$pl1 -> isEmpty())
                        @if($pl1->role_id === 2)
                        <td><a href="/{{ $pl1->path }}">{{ $pl1->file_name }}</a></td>
                        @else
                        <td>-</td>
                        @endif
                        @if($pl1->role_id === 3)
                        <td><a href="/{{ $pl1->path }}">{{ $pl1->file_name }}</a></td>
                        @else
                        <td>-</td>
                        @endif
                      </tr>
                        @break
                    @endif
                  @endforeach

>Solution :

The variable $paperlist1 is the Collection, so ->isEmpty() will only work on $paperlist1 and not on $pl1 as $pl1 is each value of the collection.

So, @if(!$pl1 -> isEmpty()) (that could be more readable if you used @if($pl1->isNotEmpty())) will not make sense at all, because you already have data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading