Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel multiuser settings #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace App\Modules\LaravelSettings\SettingsRepositories;

class DatabaseSettingsRepository extends \Spatie\LaravelSettings\SettingsRepositories\DatabaseSettingsRepository
{
public function updatePropertiesPayload(string $group, array $properties): void
{
$propertiesInBatch = collect($properties)->map(function ($payload, $name) use ($group) {
return [
'group' => $group,
'name' => $name,
'payload' => json_encode($payload),
];
})->values()->toArray();

foreach ($propertiesInBatch as $batch) {
$this->getBuilder()
->updateOrInsert([
'group' => $batch['group'],
'name' => $batch['name']
], ['payload' => $batch['payload']]);
}
}
}
7 changes: 7 additions & 0 deletions app/Settings/GeneralSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ class GeneralSettings extends Settings
public bool $enable_registration;
public string|null $site_logo;
public string|null $enable_social_login;

public string|null $site_language;

public string|null $default_role;

public string|null $enable_login_form;

public string|null $enable_oidc_login;

public static function group(): string
{
if (!auth()->guest()) {
return 'user.' . auth()->user()->id;
}
return 'general';
}

Expand Down
2 changes: 1 addition & 1 deletion config/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
'repositories' => [
'database' => [
'type' => Spatie\LaravelSettings\SettingsRepositories\DatabaseSettingsRepository::class,
'type' => \App\Modules\LaravelSettings\SettingsRepositories\DatabaseSettingsRepository::class,
'model' => null,
'table' => null,
'connection' => null,
Expand Down
Loading