F
Filament3mo ago
Neamix

PanalsRenderHook doesnt acce[t @script tag

I have created panals render hook in the header but when i want to implement js i get this error
Using $this when not in object context
Using $this when not in object context
my component register in appservice provider
FilamentView::registerRenderHook(
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
function () {
if (Auth::user()->role_id == DOCTOR)
return (new MessageCenter)->render();
},
);
FilamentView::registerRenderHook(
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
function () {
if (Auth::user()->role_id == DOCTOR)
return (new MessageCenter)->render();
},
);
my blade
<div>
@script
<script>
channel = window.pusher.subscribe('private-messagecenter.{{Auth::guard("admin")->user()->id}}');
channel.bind('MessageSent', function(data) {
Livewire.dispatch('MessegeReceive')
});
</script>
@endscript
</div>
<div>
@script
<script>
channel = window.pusher.subscribe('private-messagecenter.{{Auth::guard("admin")->user()->id}}');
channel.bind('MessageSent', function(data) {
Livewire.dispatch('MessegeReceive')
});
</script>
@endscript
</div>
9 Replies
brownbear1773
brownbear17733mo ago
I am new with this but i think the issue likely comes from the fact that the Auth::user() call is inside a closure. Since closures don't have access to $this, you cannot access properties or methods like you would in a class method.
Dennis Koch
Dennis Koch3mo ago
Would help if you shared the stack trace and not only the error message
Neamix
NeamixOP3mo ago
Neamix
NeamixOP3mo ago
The AppServiceProvider
Neamix
NeamixOP3mo ago
MessageCenter Class
class MessageCenter extends Component
{
public $message;
public $rand;

#[On('MessegeReceive')]
public function messages()
{
dd('dasd');
}


public function render()
{
$chatrooms = Auth::user()->chatrooms()
->with(['messages' => function ($query) {
$query->latest();
}])
->whereHas('reservation',function ($query) {
$query->where('answered',0);
})
->withCount(['messages as last_message_time' => function($query) {
$query->select(DB::raw('MAX(created_at)'));

}])
->orderByDesc('last_message_time')
->get();
// dd($chatrooms);
return view('livewire.message-center',[
'chatrooms' => $chatrooms
]);
}
}
class MessageCenter extends Component
{
public $message;
public $rand;

#[On('MessegeReceive')]
public function messages()
{
dd('dasd');
}


public function render()
{
$chatrooms = Auth::user()->chatrooms()
->with(['messages' => function ($query) {
$query->latest();
}])
->whereHas('reservation',function ($query) {
$query->where('answered',0);
})
->withCount(['messages as last_message_time' => function($query) {
$query->select(DB::raw('MAX(created_at)'));

}])
->orderByDesc('last_message_time')
->get();
// dd($chatrooms);
return view('livewire.message-center',[
'chatrooms' => $chatrooms
]);
}
}
Dennis Koch
Dennis Koch3mo ago
And the stack trace?!
Neamix
NeamixOP3mo ago
yea of course
D:\Projects\Refk Project\RefkApi\resources\views\livewire\message-center.blade
.php

: 57
require
D:\Projects\Refk Project\RefkApi\resources\views\livewire\message-center.blade
.php

: 57
require
D:\Projects\Refk Project\RefkApi\storage\framework\views\4943bc92ebba41e8b0e508149542e0ad.blade
.php

: 16
require
D:\Projects\Refk Project\RefkApi\storage\framework\views\4943bc92ebba41e8b0e508149542e0ad.blade
.php

: 16
require
Neamix
NeamixOP3mo ago
and this is the log error
Dennis Koch
Dennis Koch3mo ago
Seems like @script is causing issues. Not sure why thought. MessageCenter is a valid Livewire class?
Want results from more Discord servers?
Add your server