I have php file template that I need to fill with some data and export as "rendered_view.php". It need to be done automatically every day. So I'm trying to use the Laravel Scheduler.
So I have:
View "view_to_render.blade.php"
<?
$someVariable = "{{$variable}}";
require_once("includes/php_file.php");
?>
Controller "MiscController.php"
public function testRenderView(){
file_put_contents(public_path('rendered_view.php'), view('view_to_render', ['variable' => '123456'])->render());
}
Route
Route::get('testRenderView', 'MiscController@testRenderView');
Console/Kernel.php
$schedule->call(function() {
(new MiscController())->testRenderView();
})->daily()->at('13:00');
Scenario 1: If I navigate to 127.0.0.1:8000/testRenderView, it's working and file rendered_view.php is saved in public folder with expected content:
<?
$someVariable = "123456";
require_once("includes/php_file.php");
?>
Scenario 2: If It's executed by scheduler (at 13:00), it returns error:
local.ERROR: Illuminate\View\Engines\PhpEngine::main(): Failed opening required 'includes/php_file.php' (include_path='.:') {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 64): Illuminate\View\Engines\PhpEngine::main(): Failed opening required 'includes/php_file.php' (include_path='.:')
Looks like when it's executed from Scheduler, Laravel tries to render the view as real view. I also tried to create artisan commands, but the behaviour is the same. Works fine when I execute the command on console, but doesn't when I call the command from Scheduler. Any idea why it's happening?