-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');
        });
    }

3
  • my js in for a start $data->modal is NOT valid JS Commented Jun 9, 2022 at 0:43
  • php.net/manual/en/function.echo.php Commented Jun 9, 2022 at 1:01
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Jun 9, 2022 at 3:39

2 Answers 2

0

One cannot mix PHP and JS syntax.

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

Usually it's more alike this.

Sign up to request clarification or add additional context in comments.

Comments

-1

Try this.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.