Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nolros's avatar
Level 23

L5 PHP Annonation Param

More of a reminder than a tip, but I keep forgetting so I thought I would share with all. If you are using PHP annotations and then redirect, don't forget to add param to destination annotation. Example:

    /**
     * @Get("account/activate/{code}", as="getActivate")
     * @Middleware("guest")
     */
    public function getActivate($code) {

        $user =  User::where('code','=', $code)->first();

        return  Redirect::route('getSuccess', [$user->first_name]);

    }

    /**
     * @Get("success/{firstName}", as="getSuccess")
     */
    public function authSuccess($firstName)
    {
        // stuff
    }
0 likes
2 replies
milon's avatar

nice, can you show any way to pass value on @Hears annotation method?

nolros's avatar
Level 23

This is how I use it in one of classes:

   public function register($user)
    {
        ( ! is_array($user)) ? $payload = array($user) : $payload = $user;

        $this->dispatcher->fire('UserHasRegistered', $payload);
     }

then in my email listener I have

   /**
     * @hears("UserHasRegistered")
     */
    public function emailUserActivationCode($payload)
    {

        $value = $this->userMailer->sendWelcomeMessageTo($payload);


    }

Please or to participate in this conversation.