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

Laravel – simpliest elseif

@foreach ($todos as $todo)
@if($todo->is_completed == 1)
    <tr class="bg-success">
@elseif($todo->level == 1)
    <tr class="bg-primary">
@elseif($todo->level == 2)
    <tr class="bg-warning">
@elseif($todo->level == 3)
    <tr class="bg-danger">
@endif

Hi, have i to do it more simple or its a normal practice?

>Solution :

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

Instead of using if-else, I would recommend you to use switch statement.

@foreach ($todos as $todo)
   @if($todo->is_completed == 1)
     <tr class="bg-success">
   @endif

   $level= $todo->level;

  @switch($level)
       @case('1')
           <tr class="bg-primary">
       @break
 
       @case('2')
            <tr class="bg-warning">
       @break
 
       @case('3')
            <tr class="bg-danger">
       @break
  @endswitch
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