-1

get javascript syntax error in .blade.php for get $data->modal

my controller function :

    public function buku_all($page, $modal)
    {$data = (object) [
            'sidebar' => "pelayanan",
            'breadcrumbsub' => 'Data Buku',
            'modal' => $modal
            'page' => $page
            ];
    return view('admin.buku')->with('data', $data);
    }

my js in admin/buku.blade.php

if ($data->modal == 'book') {
        $(window).on('load', function() {
            $('#modal_edit_1').modal('show');
        });
    }

2 Answers2

0

One cannot mix PHP and JS syntax.

@isset ($data)
   <script>
       let data = {{ json_encode($data) }};
       ...
   </script>
@endisset

Usually it's more alike this.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
-1

Try this.

@isset ($data)
   <script>
       var data = "{{ json_encode($data) }}";
       console.log(data);
       ...
   </script>
@endisset