ホーム > Laravel > How to pass an array of data from Laravel's blade to a Vue component
Laravel

How to pass an array of data from Laravel's blade to a Vue component

Thank you for your continued support.
This article contains advertisements that help fund our operations.

⇨ Here is the table of contents for Laravel articles

I wrote about how to pass an array of data from Laravel's blade to a Vue component.

If you make a mistake, you will get an error like this:

htmlspecialchars() expects parameter 1 to be string, array given (View: /laravel-project/resources/views/home.blade.php)

Conclusion

Use @json and v-bind.

<vue-component :users="@json($users)"></vue-component>

Notes

1. Do not forget to add @json (the initial error occurs if this is missing. The parameter type must be a string, so convert it to JSON)
2. Use v-bind

Reference

Laravel Official Documentation

Summary

That's all.

Since it's written in the Laravel official documentation, it seems good to remember it!

For feedback or complaints, please contact me via Twitter DM.

That's all!

Popular Articles

Deploying a PHP7.4 + Laravel6 project to AWS EC2

Implementing breadcrumbs in Laravel with laravel-breadcrumbs

Please Provide Feedback
We would appreciate your feedback on this article. Feel free to leave a comment on any relevant YouTube video or reach out through the contact form. Thank you!