Can you share the controller?
problem with datatable
my datatable not found, brower send me this error:ErrorException (E_NOTICE) Undefined variable: request C:\laragon\www\faustinumApp\app\Http\Controllers\PaiementAjaxController.php
Thanks for the consideration, this problem has been handled, my current concern is as follows: When I try to display my datatable, I have this error: compact (): Undefined variable: payments see my controller below: use App\Paiement; use Illuminate\Http\Request; use DataTables; class PaiementAjaxController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if ($request->ajax()) { $data = Paiement::latest()->get(); return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Edit" class="edit btn btn-primary btn-sm editPaiement">Modifier</a>';
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Delete" class="btn btn-danger btn-sm deletePaiement">Supprimer</a>';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
return view('paiementAjax.index',compact('paiements'));
}
Per the error, it seems you are trying to compact and return a $payment variable to the paiementAjax.index view, but I don't see where you set this variable in your controller method. You set a variable called $data perhaps you are meaning to return that to the view instead, like:
return view('paiementAjax.index',compact('data'));
use App\Paiement; use Illuminate\Http\Request; use DataTables; class PaiementAjaxController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if ($request->ajax()) { $data = Paiement::latest()->get(); return Datatables::of($data) ->addIndexColumn() ->addColumn('action', function($row){
$btn = '<a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Edit" class="edit btn btn-primary btn-sm editPaiement">Modifier</a>';
$btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="Delete" class="btn btn-danger btn-sm deletePaiement">Supprimer</a>';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
return view('paiements.index',compact('data'));
}
ErrorException (E_NOTICE) compact(): Undefined variable: data
Please format your code by putting 3 backticks ``` on a line before and after each code block
You have to use below one in top of your controller,
use Illuminate\Http\Request;
Please or to participate in this conversation.