So here are the index and destroy function but the delete button is not working properly and just giving me a blank page with the ID
Controller
//this is the index
public function index()
{
if(request()->ajax()) {
return datatables()->of(Aya_div::select('*'))
->addIndexColumn()
->addColumn('action', function ($id) {
$btn = '<a href="'.route("aya_div.show", $id).'" class="edit btn btn-info btn-sm">View</a>';
$btn = $btn.'<a href="'.route("aya_div.edit", $id).'" class="edit btn btn-primary btn-sm">Edit</a>';
$btn = $btn.'<a href="'.route("aya_div.destroy", $id).'" class="edit btn btn-danger btn-sm">Delete</a>';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
return view('aya_div.index');
}
//this is the destroy function
public function destroy($id)
{
$div = Aya_div::find($id);
$div->delete();
return redirect()->route('aya_div.index')->with('successs', 'Data Deleted');
}
I am expecting the way of defining a method in a button
What you are currently calling is the GET REQUEST, while instead you need to use laravel DELETE REQUEST you can follow the below example:
Step 1: Pass data-id= ID
Step 2: Call the delete button to ajax
Full code:
If you click the first delete button, it will pass the
ID=123, if you click the second button you will pass theID=555, you can also also accomplish the same thing using tables, but hopefully this serves as a sufficient reference to what you can do.