0

I'm using Laravel blades/views to generate files by templates from the custom console command. Unfortunately, any of the variants from official documentation are not working.

This is how I'm trying to pass data to the view:

$info = 'Some info';
view('my_template', compact('info'));

or

view('my_template', ['info'=>'Some info']);

or

view('my_template')->with(['info'=>'Some info']);

or

use \View as View;
View:make('my_template',['info'=>'Some info']);

I would highly appreciate any help!

Vlad Rovner
  • 194
  • 4
  • 11
  • 2
    what doesn't work? what is happening? what are you expecting to happen? what are you even trying to do with this view in your command? – lagbox Feb 21 '21 at 09:58
  • i think you need use View::make('my_template',['info'=>'Some info'])->render(); – Mustafa Goda Feb 21 '21 at 11:05
  • 1
    Render(), when applied to a view, will generate the corresponding raw html and store the result in a variable. – Mustafa Goda Feb 21 '21 at 11:13
  • Do you actually return a view page? It could be trivial, but if you don't return a view page (blade) how are you going to access the passed data? Please show us your `return` statement. – Dimitri Mostrey Feb 21 '21 at 11:27
  • You wrote _console command_ - there is no view just an output to the console. Can you please show your full command class? Please paste as inline code in the OP. – codedge Feb 21 '21 at 14:24
  • @lagbox, what doesn't work? - data are not defined in the view. what is happening? - nothing. what are you expecting to happen? - get rendered view with predefined variables. what are you even trying to do with this view in your command? - generate a filled template and save it as a file. – Vlad Rovner Feb 22 '21 at 01:10
  • thanks ... how are you attempting to get the rendered content from the view btw? – lagbox Feb 22 '21 at 02:13
  • Thank You! I'm testing result with info function: `$html = view('my_template',['info'=>'Some info']); $this->info($html);` It returns all view content correctly. BUT when I'm trying to use variable in blade, like `{{$info}}` it shows error `variable not defined` – Vlad Rovner Feb 22 '21 at 02:22

0 Answers0