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:
<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
Advertisement
Answer
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.