PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 17, 2022

[FIXED] How to get array values using foreach in laravel

 May 17, 2022     laravel, laravel-5, laravel-blade, php     No comments   

Issue

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 class="collapse-button collapsed"
                    data-toggle="collapse"
                    href="#collapse_&&&&&"
                    aria-expanded="true"
                    aria-controls="collapse_&&&&&"
                    onclick="loadDealsFor(&&&&&, 'precedence');"
                    style="width: 100%; display: block; margin: -10px; padding: 10px;"
                >
                    <i class="zmdi zmdi-plus"></i> <i class="zmdi zmdi-minus"></i> exists
                </a>
            </th>
        </tr>
    </thead>
@endforeach

I tried but I did not manage to duplicate the code twice, and replace the &&&&& with the values from the $group_by_precedence array; first true and then false.

Currently the bad solution is to duplicate the code in the view, and just change the &&&&& with true and false.


Solution

Hope it might help:

<thead>
    <tr>
        @foreach ($group_by_precedence as $value)
            <th colspan="8">
                <a class="collapse-button collapsed"
                    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 class="zmdi zmdi-plus"></i> <i class="zmdi zmdi-minus"></i> exists
                </a>
            </th>
        @endforeach
    </tr>
</thead>


Answered By - Saied Islam Shuvo
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing