How to get the value of for each loop and use it in route query parameters using laravel

I have this problem wherein I have a table from foreach loop like example below and try to pass it on a url path href="{{ url(‘grade/semester/schoolyear’)}}"

SEMESTER SCHOOL YEAR Action
1st 2020-2021 View
2nd 2019-2020 View
1st 2018-2019 View
2nd 2018-2019 View

Blade Code:

<table class="table">
                        <thead>
                            <tr >
                            <th scope="col" style="color:#1a0dab">Semester</th>
                            <th scope="col" style="color:#1a0dab">Academic Year</th>
                            <th scope="col" style="color:#1a0dab">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                        @foreach($years as $year)
                            <tr>
                             <td style="text-align: left;">{{ $year->sem}}</td>
                            <td>{{ $year->sy}} </td>
                            <td><a title="View Grade" **href="{{ url('/grade/{{$year->sem}}/{{$year->sy}}')}}"**> <i class="fas fa-file-alt"></i></a> &nbsp;&nbsp;
                                <a title="Print Grade" href="#"><i class="fas fa-print"></i></a></td>
                          
                            </tr>
                            @endforeach
                        </tbody>
            </table>

What I would like to get is the correct route: http://127.0.0.1:8000/grade/1st/2018-2019 when I click the link View of the row number 3 in my table so that it will give me the correct path.

Thank you very much for you answer.

1 thought on “How to get the value of for each loop and use it in route query parameters using laravel”

  1. You cannot evaluate the template multiple times, what you can do is to concatenate the string in order to obtain the url you want:

    {{ url('/grade/' . $year->sem . '/' . $year->sy) }}
    

    where . is the PHP operator for string concatenation

    Reply

Leave a Comment