If you just pass $private it will automatically be converted to a JSON string.
Blade to Vue: Alternative to json_encode
I forget which video it was in, but Jeffrey pointed out another way to pass a Laravel collection to vue. Currently I am using this. What is the other alternative to passing the collection data? Is it just {{ $private}}? Anyone remember what video that was in?
<basictable
:data="{{ json_encode($private) }}"
:columns="{{ json_encode($columns) }}"
>
</basictable>
When printing an object in a blade template the object is attempted to be converted to a string.
Both Eloquent models and Laravel Collection class have a __toString method that converts itself to json so anytime you would echo or print them they are automatically converted into a json string.
This is why you can just to something like {{ $user }} and it will be converted into json.
You can implement a __toString() method on any of your own classes if you want to be able to do that to them as well.
Please or to participate in this conversation.