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

Fix relationship could not be set as required #5192

Merged
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
2 changes: 2 additions & 0 deletions resources/views/formfields/relationship.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class="form-control select2-ajax" name="{{ $options->column }}"
data-get-items-field="{{$row->field}}"
@if(!is_null($dataTypeContent->getKey())) data-id="{{$dataTypeContent->getKey()}}" @endif
data-method="{{ !is_null($dataTypeContent->getKey()) ? 'edit' : 'add' }}"
@if($row->required == 1) required @endif
>
@php
$model = app($options->model);
Expand Down Expand Up @@ -163,6 +164,7 @@ class="form-control @if(isset($options->taggable) && $options->taggable === 'on'
data-label="{{$options->label}}"
data-error-message="{{__('voyager::bread.error_tagging')}}"
@endif
@if($row->required == 1) required @endif
>

@php
Expand Down
5 changes: 3 additions & 2 deletions resources/views/tools/bread/relationship-partial.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<div class="col-xs-2">
<h4><i class="voyager-heart"></i><strong>{{ $relationship->getTranslatedAttribute('display_name') }}</strong></h4>
<div class="handler voyager-handle"></div>
<strong>{{ __('voyager::database.type') }}:</strong> <span>{{ __('voyager::database.relationship.relationship') }}</span>
<strong>{{ __('voyager::database.type') }}:</strong> <span>{{ __('voyager::database.relationship.relationship') }}</span><br/>
<strong>{{ __('voyager::generic.required') }}:</strong>
<input type="checkbox" value="1" name="field_required_{{ $relationship['field'] }}" @if(!empty($relationship->required))checked="checked"@endif>
<div class="handler voyager-handle"></div>
<input class="row_order" type="hidden" value="{{ $relationship['order'] }}" name="field_order_{{ $relationship['field'] }}">
</div>
Expand Down Expand Up @@ -122,7 +124,6 @@
</div>
</div>
</div>
<input type="hidden" value="0" name="field_required_{{ $relationship['field'] }}" checked="checked">
<input type="hidden" name="field_input_type_{{ $relationship['field'] }}" value="relationship">
<input type="hidden" name="field_{{ $relationship['field'] }}" value="{{ $relationship['field'] }}">
<input type="hidden" name="relationships[]" value="{{ $relationship['field'] }}">
Expand Down
3 changes: 1 addition & 2 deletions src/Models/DataType.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ public function updateDataType($requestData, $throw = false)
);

$requestData = $this->getRelationships($requestData, $fields);

foreach ($fields as $field) {
$dataRow = $this->rows()->firstOrNew(['field' => $field]);

foreach (['browse', 'read', 'edit', 'add', 'delete'] as $check) {
$dataRow->{$check} = isset($requestData["field_{$check}_{$field}"]);
}

$dataRow->required = boolval($requestData['field_required_'.$field]);
$dataRow->required = !empty($requestData['field_required_'.$field]);
$dataRow->field = $requestData['field_'.$field];
$dataRow->type = $requestData['field_input_type_'.$field];
$dataRow->details = json_decode($requestData['field_details_'.$field]);
Expand Down