M Muqiit Faturrahman
M Muqiit Faturrahman

Reputation: 129

Laravel datatables raw columns

i have a code like this to display an action button for datatables

->addColumn('action', function () {
            return '<form id="delete" action="{{ route(' . 'admin.posts.destroy' . ', $model) }}" method="POST">
            @csrf
            @method("DELETE")
            <a href="{{route(' . 'admin.posts.edit' . ', $model) }}" class="btn btn-info">Edit</a>
            <input type="submit" class="btn btn-danger" value="Delete">
        </form>';
        })

But the @csrf and @method("DELETE") become a string/text (not method). I tried to append {{ }} in @csrf and @method("DELETE") but it doesn't work. How to change that text to method in blade templates without make a new view for action button like that?

Thank you!

Upvotes: 0

Views: 1971

Answers (1)

Autista_z
Autista_z

Reputation: 2541

@csrf replace with <input type="hidden" name="_token" value="{{ csrf_token() }}"> and @method("DELETE") with <input type="hidden" name="_method" value="delete">

Upvotes: 1

Related Questions