Livewire Component passing variable to Blade Error
Hello! I have a livewire component called Announcement and this is the code
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Announcement extends Component
{
public $message = '';
public function render()
{
return view('livewire.announcement', [
'message' => 'This is a test announcement!'
]);
}
}
This is my blade file's code in /views/livewire/announcement.blade.php
<div>
<div>
<h1>Announcement</h1>
<h1>{{ $message }}</h1>
</div>
</div>
I tried a lot of things of why the error message "Undefined variable $message" is always showing but I can't seem to find what solution is applicable.Solution:Jump to solution
I got it working bro, the solution is I deleted the Announcement Class and its View file and created a new livewire component.
16 Replies
try it like this:
Still Undefined variable $message
🤔
I registered the livewire in the AppServiceProvider using this code FilamentView::registerRenderHook(
PanelsRenderHook::BODY_START,
fn (): View => view('livewire.announcement'),
);
Try like this
This is now the error:
Just check out and I don't have a problem, what I did
This is my code in AppServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Filament\Support\Facades\FilamentView;
use Illuminate\Contracts\View\View;
use Filament\View\PanelsRenderHook;
use Illuminate\Support\Facades\Blade;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
FilamentView::registerRenderHook(
PanelsRenderHook::GLOBAL_SEARCH_BEFORE,
fn (): View => view('livewire.clock'),
);
FilamentView::registerRenderHook(
PanelsRenderHook::BODY_START,
fn (): string => Blade::render('@livewire(\'announcement\')'),
);
}
}
And this is the latest error code
what are the versions of filament and livewire?
"filament/filament": "^3.2.71",
"hasnayeen/themes": "^3.0",
"jeffgreco13/filament-breezy": "^2.3",
"laravel/framework": "^11.0",
"laravel/tinker": "^2.9",
"livewire/livewire": "^3.5",
@Pints ^^
This is the current code,
no idea now
It's okay bro, gonna find it out soon, thanks btw
Solution
I got it working bro, the solution is I deleted the Announcement Class and its View file and created a new livewire component.