Try this
<div x-data="@json($component)"> </div>
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What is the best way to get data from my database, to Alpine.JS
Say I have the following in my controller
$component = DB::table('config_pathway')
->select( 'height','width','x','y')
->get();
return view('chart', compact('component'));
In my blade template I don't seem to be able to echo the view variable directly into the x-data object
<div x-data="$component"> </div>
I have tried several variation of the above. Each attempt results in the error
Uncaught ReferenceError: $component is not defined
Yet I can access $component elsewhere in my template
Thanks
Please or to participate in this conversation.