so im working my first project in php and i ran into a problem, which im not sure how to solve. I have a fairly standart init for my controller with “create”, “edit”, “delete” etc function.
Within here i have a function called “pdf”, this is gathering the data connected to the document and setting up a printable PDF view. The function is already working, but only thru direct access of the route.
Now to my problem:
They want the pdf function to be called by a button – when i call the pdf function (defined in my controller, called in my index function in the controller) It says it´s not defined. Any ideas how to bypass this? (I´m assuming i can´t see the function from within my function?)
This is some quickly written exmaple / more or less pseudo code, since i´m not at liberty to share the original code.
<?php
class UserController {
public function index(Request $request) {
return DataTables::of(Example::all())
->addColumn('action', function($row)){
$btn = "<button onclick = 'pdf($id)'>"
}
}
public function pdf($id) {
//creates the pdf then
return $pdf->stream('Example.pdf');
}
}
?>
Thanks for any answers in advance, i hope i made my problem clear.