Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Jul 12, 2023
1 parent f9d49aa commit ff7bdfe
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Events/Settings/SettingChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Native\Laravel\Events\Settings;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class SettingChanged implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public string $key, public mixed $value)
{

}

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
13 changes: 13 additions & 0 deletions src/Facades/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Native\Laravel\Facades;

use Illuminate\Support\Facades\Facade;

class Settings extends Facade
{
protected static function getFacadeAccessor()
{
return \Native\Laravel\Settings::class;
}
}
24 changes: 24 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Native\Laravel;

use Native\Laravel\Client\Client;

class Settings
{
public function __construct(protected Client $client)
{
}

public function set($key, $value): void
{
$this->client->post('settings/'.$key, [
'value' => $value,
]);
}

public function get($key, $default = null): mixed
{
return $this->client->get('settings/'.$key)->json('value') ?? $default;
}
}

0 comments on commit ff7bdfe

Please sign in to comment.