christophrumpel / blog-laravel-real-time-notifications

47 stars 28 forks source link

Undefined syntax 'string' in RealTimeMessage and RealTimeNotification class #1

Closed NasrinAfrozKakoli closed 3 years ago

NasrinAfrozKakoli commented 3 years ago

Undefined syntax 'string' in RealTimeMessage and RealTimeNotification class.

The error was shown every time I tried to tinker the message. So, I removed the type 'string' from $message variable. And It worked perfectly.

Both class were like this after editing,

class RealTimeMessage implements ShouldBroadcast
{
    use SerializesModels;

    public $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

and

class RealTimeNotification extends Notification implements ShouldBroadcast

{
    use Queueable;
    public $message;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

You did an amazing job. Thank you so much for the easiest tutorial possible.

hnnweb commented 3 years ago

Use PHP 7.4 and "string" will work.

christophrumpel commented 3 years ago

Yeah @hnnweb is right, you need to have PHP 7.4+ to make it work properly, or remove the type hints as you did.