0

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?

1 Answer 1

4

You can use blades @json directive:

onclick="showPopUp(@json($info))"
Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure, the curly braces are needed? oO
@shaedrich No, I've just copied the original code and added the directive. thanks for mentioning it, edited.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.