title: Javascript onclick function not working laravel blade
body: <p>Developing delete function that needs confirmation before deleting with sweetalert2. 
  Here is my code tried</p>
  
  <pre><code>&lt;button class="btn btn-danger waves-effect" type="button" onclick="book({{ $book-&gt;id }})"&gt;delete&lt;/button&gt;
  &lt;form id="delete-form-{{ $book-&gt;id }}" action="{{ url('/library/books/', ['id' =&gt; $book-&gt;id]) }}" method="POST"&gt;
      {!! method_field('delete') !!}
      {!! csrf_field() !!}
  &lt;/form&gt;
  </code></pre>
  
  <p>And here is my javascript that I am pushing in my master blade</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function book(id) {
      swal({
          title: 'Are you sure?',
          text: "You won't be able to revert this!",
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: 'Yes, delete it!',
          cancelButtonText: 'No, cancel!',
          confirmButtonClass: 'btn btn-success',
          cancelButtonClass: 'btn btn-danger',
          buttonsStyling: false,
          reverseButtons: true
      }).then((result) =&gt; {
          if (result.value) {
              event.preventDefault();
              document.getElementById('delete-form-'+id).submit();
          } else if (
              // Read more about handling dismissals
              result.dismiss === swal.DismissReason.cancel
          ) {
              swal(
                  'Cancelled',
                  'Your data is safe :)',
                  'error'
              )
          }
      })
  }
  </code></pre>
  
  <p></p>
  
  <p>Use stack in master blade </p>
  
  <pre><code>@stack('customjs')
  </code></pre>
  
  <p>When clicking the delete button gets an error. Error is </p>
  
  <pre><code>books:4 Uncaught ReferenceError: book is not defined
  at HTMLButtonElement.onclick (books:4)
  </code></pre>
  
  <p>How can I solve this and show sweet alert before delete item?</p>