Skip to content

Commit 694ee1b

Browse files
committed
small readme fixes
1 parent faae6a6 commit 694ee1b

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,41 @@ php artisan migrate
7777
#### Bulk mode
7878

7979
```php
80+
use Illuminate\Database\Migrations\Migration;
81+
use Matteoc99\LaravelPreference\Enums\Cast;
82+
use Matteoc99\LaravelPreference\Factory\PreferenceBuilder;
83+
use Matteoc99\LaravelPreference\Rules\InRule;
8084

81-
$preferences = [
82-
['name' => 'language', 'cast' => Cast::STRING, 'default_value' => 'en', 'rule'=> new InRule("en", "it", "de"), 'group' => 'general'],
83-
['name' => 'theme', 'cast' => Cast::STRING, 'default_value' => 'light'],
84-
['name' => 'preferred_browser'],
85-
['name' => 'other_short_pref'],
86-
];
85+
return new class extends Migration {
8786

88-
public function up(): void
87+
88+
public function up(): void
8989
{
90-
PreferenceBuilder::initBulk($this->preferences);
90+
91+
PreferenceBuilder::initBulk($this->preferences());
9192
}
9293

9394
/**
9495
* Reverse the migrations.
9596
*/
9697
public function down(): void
9798
{
98-
PreferenceBuilder::deleteBulk($this->$preferences);
99+
PreferenceBuilder::deleteBulk($this->preferences());
100+
}
101+
102+
/**
103+
* Reverse the migrations.
104+
*/
105+
public function preferences(): array
106+
{
107+
return [
108+
['name' => 'language', 'cast' => Cast::STRING, 'default_value' => 'en', 'rule' => new InRule("en", "it", "de"), 'group' => 'general'],
109+
['name' => 'theme', 'cast' => Cast::STRING, 'default_value' => 'light'],
110+
['name' => 'configuration', 'cast' => Cast::ARRAY],
111+
];
99112
}
113+
};
114+
100115
```
101116

102117
### Working with preferences

0 commit comments

Comments
 (0)