diff --git a/src/SettingsCollection.php b/src/SettingsCollection.php index 935eb1e..262531c 100644 --- a/src/SettingsCollection.php +++ b/src/SettingsCollection.php @@ -2,18 +2,20 @@ namespace DarkGhostHunter\Laraconfig; +use DarkGhostHunter\Laraconfig\Eloquent\Setting; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Arr; use Illuminate\Support\Carbon; use Illuminate\Support\Enumerable; use Illuminate\Support\Traits\EnumeratesValues; +use RuntimeException; /** * Class SettingsCollection * * @package DarkGhostHunter\Laraconfig * - * @method \DarkGhostHunter\Laraconfig\Eloquent\Setting get(string $name, mixed $default = null) + * @method Setting get(string $name, mixed $default = null) */ class SettingsCollection extends Collection { @@ -97,7 +99,11 @@ public function set(string|array $name, mixed $value, bool $force = true): void } foreach ($name as $key => $setting) { - $this->get($key)?->set($setting, $force); + if (! $instance = $this->get($key)) { + throw new RuntimeException("The setting [$key] doesn't exist."); + } + + $instance->set($setting, $force); } } diff --git a/tests/HasConfigTest.php b/tests/HasConfigTest.php index 7687084..e1cad64 100644 --- a/tests/HasConfigTest.php +++ b/tests/HasConfigTest.php @@ -6,6 +6,7 @@ use DarkGhostHunter\Laraconfig\Eloquent\Setting; use DarkGhostHunter\Laraconfig\HasConfig; use DarkGhostHunter\Laraconfig\SettingsCollection; +use Error; use Exception; use Illuminate\Contracts\Cache\Factory; use Illuminate\Contracts\Cache\Repository; @@ -821,8 +822,8 @@ public function test_sets_value_dynamically(): void public function test_sets_doesnt_sets_property_dynamically_into_collection(): void { - $this->expectException(Exception::class); - $this->expectExceptionMessage('Property [invalid] does not exist on this collection instance'); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage("The setting [invalid] doesn't exist."); $user = DummyModel::find(1);