oliverbusk
3 months ago

Managing mass user settings

Posted 3 months ago by oliverbusk

So I just finished the two part videos https://laracasts.com/lessons/managing-mass-user-settings-part-2.

I have implemented what Jeffrey is talking about - but I am not using the mass settings on an user, but on what I call a Stream.

So a user can create multiple streams, that all can have specific settings.

My question is when registering the settings() function in the ServiceProvider:

$this->app->singleton('App\Settings', function() {
            return User::first()->settings();
});

Jeffrey is simply returning the first user (or this can be changed to return the authenticated user).

However, my question is - how can I implement this, so I can use it on a specific stream?

In my Stream model, I have this:

    /**
     * The settings class, that is used to store mass settings for a Stream.
     */
    public function settings()
    {
        return new Settings($this->settings, $this);
    }

This means I can use it like this:

$stream->settings()->notes;

However, I am not sure if this is the right approach? For example, how can I use it within a blade file?

Doing this:

{{ $stream->settings()->notes }}

I get below error:

htmlspecialchars() expects parameter 1 to be string, array given

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