php - Get the current view in a Laravel controller -


What do I try to do : I want to create a PDF of the current view More details: : I have found many customers and I want to create a button on each page so that I can generate a PDF of each client description.

Laravel Package:

What have I done so far :

  1. I added DomPdf to my application
  2. I added a print controller to an root :: resource (

  class print controller extended \ BaseController {Public function show () {$ Pdf = PDF :: loadView ('clients.show'); Return $ pdf-> Stream ();}}  
  1. My view contains a link (2 versions)

{{HTML :: linkAction ('printcountry @ show', 'pdf', array (), s Queen ('class' => 'BTN BTN primary bridge-right aggregate 10'))}}

  & lt; a href = "{{URL: from ('Imprimer /' $ Client-> ID)}} & gt; Pdf2 & lt; / a & gt;  

My question : Controller current view (example : Client / 1) How to pass the code so that the controller can generate a PDF of the existing page?

You have to set a variable that has the current view name, because any method for it Mit is not. We can use the View: Composer , which is basically a callback when a view is provided.

  see :: composer ('*', function ($ view) {see :: share ('view_name', $ view-> getName ());};  

If it only affects certain views, you can also restrict it to * by changing it to another mask.

So you can now:

  {{HTML :: link action ('print controller @ show', 'pdf', array ($ visual_name), array ('Class' = & gt; 'BTN BTN-Primary Bridge-Right Amgrate 10'))}}  

and get it into your controller:

 < Code> public function show ($ viewName) {// ...}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -