Dronax
8 months ago

Laravel observer check if user is logged

Posted 8 months ago by Dronax

I have observer:

<?php

namespace App\Observers;

use App\Comment;

class CommentObserver
{
    /**
     * Handle the Comment "created" event.
     *
     * @param  \App\Comment $comment
     * @return void
     */
    public function created(Comment $comment)
    {
        //
    }
}

I need to check if a user is logged. Can I add A user model to check if a user is logged? I need process this observe only if user is guest.

Middleware not working in observe.

In comment model:

public function boot()
{
    $this->observe(CommentObserver::class);
}

Please sign in or create an account to participate in this conversation.