Reputation: 19
I tried to access model TemporarySubject via my blade file. If the data exist in the model, my blade will show button red in colour else it shows a button with the default colour
Below are some of my code in blade. It seems like the code doesn't run into the @if @else condition because the output shows all button with red colour even the data do not exist in the model
@if ($rows->S4=='1')
@if (App\TemporarySubject::where('subject_name','=','S4'))
<button class="btn btn-danger btn-mini" title="Digital Logic">SCSR1013(S4)</button>
@else
<button class="btn btn-mini" title="Digital Logic">SCSR1013(S4)</button>
@endif
@endif
The output should show the button in default colour because in temporary_subjects does not contain subject_name with 'S4' value, but it shows a red colour button instead. Hopefully, someone can help me with this problem. Thanks in advance
Upvotes: 1
Views: 6773
Reputation: 14298
Your statement always returns true as it is, hence the reason of seeing the red button always. You should change your condition to something like this:
App\TemporarySubject::where('subject_name', 'S4')->exists(); // default is = so no reason to add it again.
Just an extra tip: it will be better to share this condition through the controller instead.
Upvotes: 2