laravel-welcome-notification icon indicating copy to clipboard operation
laravel-welcome-notification copied to clipboard

Attempt to read property "welcome_valid_until" on string

Open RoguePoma opened this issue 1 year ago • 1 comments

Hello, I've used this package with Laravel 8, and it worked a treat! Now I am working on a new project on Laravel 9 and whatever I do I can't get it to work.

Php Version: 8.1.6 Laravel Version: 9.19.0

This is the error message I receive: Attempt to read property "welcome_valid_until" on string

Looking deeper, it looks like the request in the WelcomesNewUsers doesn't pass a user object and just the id integer. But im unsure if I'm looking in the right place.

Has anyone faced this issue? Or know a solution?

RoguePoma avatar Jul 07 '22 13:07 RoguePoma

I am using it on Laravel 9 without any problem. Did you follow the instructions or did you modify anything specific? Maybe show some code.

dominikgeimer avatar Jul 15 '22 09:07 dominikgeimer

I'm also getting this error after trying to install this package for the first time today. I followed the setup instructions exactly as described.

https://flareapp.io/share/xPQoY0k5#F47

squpshift avatar Nov 09 '22 21:11 squpshift

I resolved this by creating my own WelcomesNewUsers middleware

<?php

namespace App\Http\Middleware;

use App\Models\User;
use Carbon\Carbon;
use Closure;
use Symfony\Component\HttpFoundation\Response;

class WelcomesNewUsers
{
    public function handle($request, Closure $next)
    {

        if (! $request->hasValidSignature()) {
            abort(Response::HTTP_FORBIDDEN, __('The welcome link does not have a valid signature or is expired.'));
        }

        $user = User::find($request->user)->first();

        if (! $user) {
            abort(Response::HTTP_FORBIDDEN, __('Could not find a user to be welcomed.'));
        }

        if (is_null($user->welcome_valid_until)) {
            abort(Response::HTTP_FORBIDDEN, __('The welcome link has already been used.'));
        }

        if (Carbon::create($user->welcome_valid_until)->isPast()) {
            abort(Response::HTTP_FORBIDDEN, __('The welcome link has expired.'));
        }

        return $next($request);
    }
}

squpshift avatar Nov 09 '22 21:11 squpshift