I’m passing data from my controller to javascript.
public function index() { $events = Eventcalendar::get()->pluck('event'); return view('eventcalendar.index',compact('events')); }
this is I do it in the blade
<script type="text/javascript"> var data = {!! $events !!} console.log(data) //the result is in the screenshot </script>
how can I remove the backslash in the JSON data?
Note: event column datatatype is JSON
I’m using LARAVEL 7
Thank you
Advertisement
Answer
Solved it by adding
protected $casts = [ 'event' => 'array' ];