I created simple app and after deploying app on remote server i have issue with code.
But.. on my local machine this code works fine, i even pulled code again from git and installed again on my local machine and it’s working without any issues.
Error that i have after visiting app.com:
Undefined variable $form
web.php:
Route::view('/', 'home')
->middleware(['auth']);
View home.blade.php
...
<div>
<livewire:ListQrcode />
</div>
Livewire component: ListQrcode.php
class ListQrCode extends Component
{
public $qrCodes;
public QrCode $selectedQrCode;
public string $selectedTitle = '';
public string $selectedDescription = '';
public string $selectedCode = '';
public bool $createQrcode = false;
public bool $showDrawer2 = false;
public CreateQrcode $form;
public function render()
{
$this->qrCodes = QrCode::with('tags')->orderBy('created_at', 'desc')->get();
return view('livewire.ListQrcode',
['qrCodes' => $this->qrCodes]
);
}
}
Livewire Form:
class CreateQrcode extends Form
{
#[Validate('required', 'string', 'min:3')]
public $code = '';
#[Validate('required', 'string', 'max:255')]
public $title = '';
...
}
View that code throw error,
<div class="flex justify-center min-h-[296px] p-8">
@if($form->code)
<div class="p-4 dark:bg-gray-600 rounded-lg">
{!! QrCode::size(200)->generate($form->code) !!}
</div>
@endif
</div>
From some reason, PHP don’t see $form variable on remote machine, when i comment problematic variable in template, then i have issue with another variable that is undefined.
What i should check to resolve that problem? It’s seems that PHP have issues with visibility of variables somehow.
Local machine:
- Windows 11
- NGINX
- PHP 8.3
Remote machine:
- Ubuntu 23
- NGINX
- PHP 8.3
2
Answers
Run php artisan config:clear and php artisan view:clear on your remote server. Sometimes, cached views or configurations can cause issues.
You should pass the $form variable to the view from the render() method in your ListQrCode component.