Here I have a foreach loop of teachers with their associated relationships which are reviews. As I loop through the teacher if they have no relationship or review I want to print "No Reviews" in the containing div. The code i use now works, however if one teacher has a review the other classes remain empty instead of saying No Review. Is there a way in laravel or in js i can do this? It's probably a simple solution for this. Can someone help me out?
HTML:
@foreach($teachers as $teacher)
<div class="item{{{ $isFirst ? ' active' : '' }}}">
<div class = "deck">
<div class = "row marg">
<div class="col-md-8">
<div class = "stdnt">
<h1>Teacher Info</h1>
{!! Form::model( $student, ['url' => ['tchUpd', $teacher->id], 'method' => 'post', 'role' => 'form'] ) !!}
<h1>{{ucwords($teacher->name)}}</h1>
<div class = "form-group fga">
{!!Form::label('title', 'NickName:', ['class' => 'control-label lad']) !!}
{!!Form::text('nick', $teacher->nick, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Email:', ['class' => 'control-label lad']) !!}
{!!Form::text('email', $teacher->email, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Position:', ['class' => 'control-label lad']) !!}
{!!Form::text('pack', $teacher->position, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Bio-Short:', ['class' => 'control-label lad']) !!}
{!!Form::text('short', $teacher->short, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Prof/Edu:', ['class' => 'control-label lad']) !!}
{!!Form::text('profedu', $teacher->profedu, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Interests:', ['class' => 'control-label lad']) !!}
{!!Form::text('interest', $teacher->interest, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::label('title', 'Pitch:', ['class' => 'control-label lad']) !!}
{!!Form::text('why', $teacher->why, ['class'=> 'input-mini ina'])!!}
</div>
<div class = "form-group fga">
{!!Form::submit('Submit', ['class'=> 'btn btn-danger form-control'])!!}
</div>
{!! Form::close() !!}
</div>
</div>
<div class = "col-md-4">
<div class = "teac">
<h1>Teacher Info</h1>
<div id = "user-profile" class = "addyphoto" style = "background-image: url(/assets/image/{{$teacher->photo}})"> </div>
{!! Form::model( $student, ['url' => ['tchUpd', $teacher->id], 'method' => 'post', 'role' => 'form', 'novalidate' => 'novalidate', 'files' => true] ) !!}
<div class = "form-group fga">
{!!Form::label('title', 'Picture:', ['class' => 'control-label lad']) !!}
{!!Form::text('photo', $teacher->photo, ['class'=> 'input-mini ina tch'])!!}
</div>
<div class = "form-group fga">
{!! form::file('newphoto', null) !!}
{!!Form::submit('Submit', ['class'=> 'btn btn-danger form-control'])!!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<div class = "mask flow">
<div class = "row-fluid marg reviewblock">
@foreach($teacher->reviews as $review)
<div class = "ablock">
<h1>{{ucwords($review->title)}}</h1>
<p>{{$review->created_at}}</p>
<p>{{$review->title}}</p>
<p>{!!$review->description!!}</p>
</div>
@endforeach
</div>
</div>
{{--*/ $isFirst = false; /*--}}
</div>
JS
if ( $('.reviewblock').children().length == 0 ) {
$(this).append("<div class = 'empty'><h1>No Reviews</h1></div>");
}
/--------------second attempt ---------/
if (isEmpty($('.reviewblock'))) {
$('.reviewblock').append("<div class = 'empty'><h1>No Reviews</h1></div>");
}