Home > Blockchain >  How to get array values using foreach in laravel
How to get array values using foreach in laravel

Time:04-28

I am new to laravel and php. I have this code in one of my controllers

$group_by_precedence = array("true", "false");

and this code in the view

@foreach  ($group_by_precedence as $value)

                    <thead>
                        <tr>
                            <th colspan="8">
                                <a  data-toggle="collapse" href="#collapse_&&&&&" aria-expanded="true" aria-controls="collapse_&&&&&" onclick = "loadDealsFor(&&&&&, 'precedence');"  style="width: 100%;display: block;margin: -10px;padding: 10px;">
                                    <i ></i> <i ></i> exists
                                </a>
                            </th>
                        </tr>
                    </thead>
                    
                @endforeach 

I tried and not managed to know how to make the code in the view to be duplicated twice, and replace the &&&&& with the values from the $group_by_precedence array, first the true and second the false. currently the bad solution is to duplicate the code in the view, and just change the &&&&& true and false. can someone assist?

CodePudding user response:

Hope it might help

<thead>
    <tr>
        @foreach  ($group_by_precedence as $value)
            <th colspan="8">
                <a  
                    data-toggle="collapse" 
                    href="{{ '#collapse_' . $value }}" 
                    aria-expanded="true" 
                    aria-controls="{{ 'collapse_' . $value }}" 
                    onclick = "loadDealsFor({{ $value }}, 'precedence');"  
                    style="width: 100%;display: block;margin: -10px;padding: 10px;">
                    <i ></i> <i ></i> exists
                </a>
            </th>
        @endforeach
    </tr>
</thead> 

CodePudding user response:

In your blade file you can print the vars with {{ $var }} . like that:

$group_by_precedence = array("true", "false");

@foreach  ($group_by_precedence as $value)
  <p>Your value is: {{ $value }}</p>
 @endforeach 
  • Related