0

This is my code :

public function getRolesData()
    {
        $roles = Role::All();
        return Datatables::of($roles)      
            ->addColumn('action', function ($role) {
                return "{!! Form::open(array('method'=>'DELETE', 'route' => array('admin.role.destroy',".$role->id."))) !!}
                        {!! Form::submit('Delete', array('class'=>'btn btn-danger')) !!}
                        {!! Form::close() !!}
                        ";
                })            
                ->make(true);
    }

In 'action' column in view, I get the same code :

{!! Form::open(array('method'=>'DELETE', 'route' => array('admin.role.destroy',1))) !!} {!! Form::submit('Delete', array('class'=>'btn btn-danger')) !!} {!! Form::close() !!} 

No submit button is appeared ! what's the mistake in my code ?

1
  • It doesn't work :/ In fact when I use the basic form of forms like this : ... ->addColumn('action', function ($role) { return "<form action='role/destroy/".$role->id."' method='Post'> ... </form> "; }) It works but an other error appears : TokenMismatchException in VerifyCsrfToken.php line 53: Commented Dec 15, 2015 at 17:36

1 Answer 1

1

In your example you're using blade sintax which won't work inside your controller as it's not a blade file.

Try:

return  \Form::open(array('method'=>'DELETE', 'route' => array('admin.role.destroy',".$role->id."))) .
        \Form::submit('Delete', array('class'=>'btn btn-danger')) .
        \Form::close();

Alternatively, you could move the form in to a blade file

e.g. views/admin/role/partials/datatables-form.blade.php (or wherever makes sense for your app) and just return that view file instead.

i.e.

return view('admin.role.partials.datatables-form', compact('role'))

admin/role/partials/datatables-form.blade.php

{!! Form::open(array('method'=>'DELETE', 'route' => array('admin.role.destroy',".$role->id."))) !!}
{!! Form::submit('Delete', array('class'=>'btn btn-danger')) !!}
{!! Form::close() !!}

Hope this helps!

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

1 Comment

Thanks a lot :))) You missed render() method ^^ return view('admin.role.partials.datatables-form', compact('role'))->render()

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.