Skip to content

Commit 4d92819

Browse files
committed
Refactor AddHasManyModel action to exclude hidden fields from saving and remove initial year configuration from nova.php
1 parent 37c07b5 commit 4d92819

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

app/Nova/Actions/AddHasManyModel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Laravel\Nova\Actions\Action;
1010
use Laravel\Nova\Fields\ActionFields;
1111
use Laravel\Nova\Fields\BelongsTo;
12+
use Laravel\Nova\Fields\Hidden;
1213
use Laravel\Nova\Http\Requests\NovaRequest;
1314

1415
class AddHasManyModel extends Action
@@ -49,10 +50,10 @@ public function handle(ActionFields $fields, Collection $models)
4950
{
5051
$model = app('App\Models\\'.Str::studly($this->modelName));
5152
foreach ($this->fields as $field) {
52-
if (($field->resourceClass ?? null) == null && $field->saveOnActionRelation) {
53+
if (($field->resourceClass ?? null) == null && ! $field instanceof Hidden) {
5354
$model->{$field->attribute} = $fields->{$field->attribute};
5455
}
55-
if ($field instanceof BelongsTo && $field->saveOnActionRelation) {
56+
if ($field instanceof BelongsTo && ! $field instanceof Hidden) {
5657
$model->{Str::snake($field->attribute.' id')} = $fields->{$field->attribute}->id;
5758
}
5859
}

config/app.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,13 @@
123123
'store' => env('APP_MAINTENANCE_STORE', 'database'),
124124
],
125125

126+
/*
127+
|--------------------------------------------------------------------------
128+
| Initial Years in Year Option On login form
129+
|--------------------------------------------------------------------------
130+
|
131+
*/
132+
133+
'initialyear' => env('NOVA_INITIAL_YEAR', 2024),
134+
126135
];

config/nova.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,4 @@
203203
'stopped' => '/',
204204
],
205205

206-
/*
207-
|--------------------------------------------------------------------------
208-
| Initial Years in Year Option On login form
209-
|--------------------------------------------------------------------------
210-
|
211-
*/
212-
213-
'initialyear' => env('NOVA_INITIAL_YEAR', 2024),
214206
];

0 commit comments

Comments
 (0)