edvinaskrucas / notification

Notification package for Laravel
MIT License
525 stars 99 forks source link

Laravel 5.8 Support #93

Closed diggersworld closed 5 years ago

diggersworld commented 5 years ago

Is this package still being maintained?

I'm hitting the following issue with the latest Laravel release (5.8).

1/4 in vendor/edvinaskrucas/notification/src/Krucas/Notification/Collection.php:6 "Declaration of Krucas\Notification\Collection::add(Krucas\Notification\Message $message) should be compatible with Illuminate\Support\Collection::add($item)
kw-pr commented 4 years ago

How did you fix that?

diggersworld commented 4 years ago

@kw-pr I didn't, I switched to a different package.

kw-pr commented 4 years ago

What did you use? I spend an hour now on trying to get this package running again and I am on the point to throw it out anyway. It is not worth the trouble. I could have write the functions I need in the same time.

diggersworld commented 4 years ago

@kw-pr I switched to this spatie flash package, it's very lightweight, so you might want to check whether it has what you need first.

kw-pr commented 4 years ago

@diggersworld Thanks a lot!

True, very lightweight. I needed multiple messages. Throw a class together myself:

class HtmlNotification
{
    public static function addMessage($class, $message): void
    {
        $messages = session()->get('messages', []);
        if (!isset($messages[$class]))
        {
            $messages[$class] = [];
        }
        $messages[$class][] = $message;
        session()->flash('messages', $messages);
    }

    public static function getAll()
    {
        return session()->pull('messages', []);
    }

    public static function error($message): void
    {
        self::addMessage('error', $message);
    }

    public static function success($message): void
    {
        self::addMessage('success', $message);
    }
}

Dependency problem solved forever.