0
(function () {
        new _vue2.default({
            el: 'body',

            data: {
                tableData: {
                    options: {
                        sortable: true,
                        editable: true,
                        pageCount: 10
                    },

                    columns: [{
                        value: 'id',
                        text: 'No',
                        sortable: true,
                        editable: false
                    }, {
                        value: 'name',
                        text: 'Name',
                        sortable: false,
                        editable: false,
                        isHTML: true
                    }, {
                        value: 'items',
                        text: '#of Items',
                        sortable: true,
                        editable: false
                    }, {
                        value: 'total',
                        text: 'Total',
                        sortable: true,
                        editable: false
                    },  {
                        value: 'click',
                        text: '',
                        sortable: false,
                        editable: false,
                        isHTML: true
                    },],

                    rows: [],

                    onPageChanged: function onPageChanged(page) {
                        console.log('Current page is ' + page);
                    }
                }
            },

            ready: function ready() {
                console.log(invoice.length);
                var invoices = invoice;
                var length = invoice.length;

                for (var i = 0; i < length; i++) {
                    var obj = {
                        id: {
                            value: i + 1
                        },

                        name: {
                            value: '<a href="update/'+ invoices[i].id + '">' + invoices[i].invoice + '</a>'

                        },

                        items: {
                            value: invoices[i].items ,

                        },

                        total: {
                            value: invoices[i].alltotal ,

                        },



                        click: {
                            value: '<a href="pdf/'+ invoices[i].id + '">PDF</a>&nbsp;&nbsp;  <form method="POST" action="remove/'+ invoices[i].id + '"><input type="hidden" name="_method" value="DELETE"><button type="submit">Remove</button></form>'
                        },
                    };

                    this.tableData.rows.push(obj);
                }
            },


            components: {
                DataTable: _DataTable2.default
            }
        });
    })();

I want to create delete form in click:{} because I want to use rout delete function in laravel 5.4. My html table is built with vue.js.So I need to write html code in vue.js. I get this error (TokenMismatchException in VerifyCsrfToken.php line 68:). If anyone know please answer me.

2
  • you need to post with laravel token. Commented Jun 1, 2017 at 4:54
  • yes I know. But I don't know how to call csrf_field() in delete form(click:{}). Commented Jun 1, 2017 at 4:56

2 Answers 2

1

First, add {{ csrf_token() }} in your page.

Then add the following line in your delete form.

<input type="hidden" name="_token" value="' + document.getElementsByName('_token')[0].value + '">
Sign up to request clarification or add additional context in comments.

1 Comment

Or you could just use {!! csrf_field() !!} which generates the field for you.
0

Add this in your <head> tag:

<meta name="csrf-token" content="{{ csrf_token() }}" />

2 Comments

this is my index.blade.php
<!DOCTYPE html> <html lang="en"> <head> <meta name="csrf-token" content="{{ csrf_token() }}" /> </head> <body> <div class="panel-body" id="app"> <data-table :data-table="tableData"></data-table> <script type="text/javascript"> var invoice = {!! json_encode($invoice->toArray()) !!}; </script> <script src="{{asset('js/vueapp.js')}}"></script> </div> </body> </html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.