Search code examples
jquerylaraveltreelaravel-blade

unable to convert my data to jquery variable in tree replacing " with &quot in jquery laravel


i have a variable in blade {{$data}}. i want to use it in jquery variable in tree reference(https://www.amcharts.com/docs/v5/reference/tree/)

if i try {{ str_replace(['";"'],[';'], json_encode([$data]))}} in blade it gives

[{
             name: "ali", value: 88,
             joindate: ""11/09/2022", email: "{{\Auth::user()->email}}",
             photo: "01.png", level: 6,
             children: [{       
                 name: "salim", level: 1,
                 joindate: "11/09/2022", email: "sssss@lutota.com",
                 photo: "02.png", level: 4,
                 },]
         }];

when i copy this code in data variable like static text in jquery like

let data = [{
             name: "ali", value: 88,
             joindate: ""11/09/2022", email: "{{\Auth::user()->email}}",
             photo: "01.png", level: 6,
             children: [{       
                 name: "salim", level: 1,
                 joindate: "11/09/2022", email: "sssss@lutota.com",
                 photo: "02.png", level: 4,
                 },]
         }];

it works fine in tree but when i want to use variable instead of code like below it display nothing

let data = '{{json_encode([$data])}}'; 

nothing works...please help


Solution

  • replace let data with this:

    let data = {!! json_encode($data) !!};
    

    or with this :

    let data = <?php echo json_encode($data); ?>;
    

    or with this :

    let data = @json($data); //for blade only