CSRF on YAJRA datatable Laravel5.5 not working

前端 未结 3 1738
感情败类
感情败类 2021-01-24 08:20

I have this code where I needed to store in a variable so I display it in view, I\'ve tried different approach of packing the \"Form header\" and using CSRF is not working

3条回答
  •  猫巷女王i
    2021-01-24 08:57

    Return the form to another blade like view/products/datatables.blade.php

    Example: The controller should looks like:-

    public function getproducts()
    {
    $product = Product::all(); //Product is Model name
    
    return Datatables::of($product)
        ->addColumn('action', function($product)
        {
              return view('product.datatables', compact('product'))->render();
        })->make(true);
    
    }
    

    And the view should look as below:

    Edit
    
    {{ method_field('DELETE') }} {{ csrf_field() }}

    It will work just fine. Because the mustache {{}} can't be read in the controller. We redirect the things to the blade

提交回复
热议问题