HuA
HuA

Reputation: 111

sending eloquent object to JavaScript function

I am trying to pass Laravel eloquent object to JavaScript function. I have this code:

                @php
                    {{$count = 1;}}
                @endphp
                @foreach($user_infos as $info)
                    <tr onclick="">
                        <th scope="row">{{$count++}}</th>
                        <td hidden>{{$info->id}}</td>
                        <td>{{$info->name}}</td>
                        <td>{{$info->email}}</td>
                        <td>{{$info->workplace_name}}</td>
                        <td>{{$info->department_name}}</td>
                        <td><i class="fa-solid fa-pen-to-square" onclick="showPopUp({{$info}})"
                               style="cursor: pointer; color: blue"></i></td>
                    </tr>
                @endforeach

I want to pass the current object ($info) to the function (showPopUp).

Any suggestion?

Upvotes: 0

Views: 208

Answers (1)

Behzad
Behzad

Reputation: 572

You can use blades @json directive:

onclick="showPopUp(@json($info))"

Upvotes: 4

Related Questions