@if(isset($options->model) && isset($options->type))
@if(class_exists($options->model))
@php $relationshipField = $row->field; @endphp
@if($options->type == 'belongsTo')
@if(isset($view) && ($view == 'browse' || $view == 'read'))
@php
$relationshipData = (isset($data)) ? $data : $dataTypeContent;
$model = app($options->model);
$query = $model::where($options->key,$relationshipData->{$options->column})->first();
@endphp
@if(isset($query))
{{ $query->{$options->label} }}
@else
{{ __('voyager::generic.no_results') }}
@endif
@else
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);
$query = $model::where($options->key, old($options->column, $dataTypeContent->{$options->column}))->get();
@endphp
@if(!$row->required)
{{__('voyager::generic.none')}}
@endif
@foreach($query as $relationshipData)
column, $dataTypeContent->{$options->column}) == $relationshipData->{$options->key}) selected="selected" @endif>{{ $relationshipData->{$options->label} }}
@endforeach
@endif
@elseif($options->type == 'hasOne')
@php
$relationshipData = (isset($data)) ? $data : $dataTypeContent;
$model = app($options->model);
$query = $model::where($options->column, '=', $relationshipData->{$options->key})->first();
@endphp
@if(isset($query))
{{ $query->{$options->label} }}
@else
{{ __('voyager::generic.no_results') }}
@endif
@elseif($options->type == 'hasMany')
@if(isset($view) && ($view == 'browse' || $view == 'read'))
@php
$relationshipData = (isset($data)) ? $data : $dataTypeContent;
$model = app($options->model);
$selected_values = $model::where($options->column, '=', $relationshipData->{$options->key})->get()->map(function ($item, $key) use ($options) {
return $item->{$options->label};
})->all();
@endphp
@if($view == 'browse')
@php
$string_values = implode(", ", $selected_values);
if(mb_strlen($string_values) > 25){ $string_values = mb_substr($string_values, 0, 25) . '...'; }
@endphp
@if(empty($selected_values))
{{ __('voyager::generic.no_results') }}
@else
{{ $string_values }}
@endif
@else
@if(empty($selected_values))
{{ __('voyager::generic.no_results') }}
@else
@foreach($selected_values as $selected_value)
{{-- TODO: This could allows us to expand on posts attachments previews on admin --}}
@if($relationshipField === 'payment_request_hasmany_attachment_relationship')
@include('vendor.voyager.partials.voyager-file-preview-box', ['asset' => $selected_value])
@else
{{ $selected_value }}
@endif
@endforeach
@endif
@endif
@else
@php
$model = app($options->model);
$query = $model::where($options->column, '=', $dataTypeContent->{$options->key})->get();
@endphp
@if(isset($query))
@foreach($query as $query_res)
@if($relationshipField === 'payment_request_hasmany_attachment_relationship' && $query_res instanceof \App\Model\Attachment)
@include('vendor.voyager.partials.voyager-file-preview-box', ['asset' => $query_res->filename])
@else
{{ $query_res->{$options->label} }}
@endif
@endforeach
@else
{{ __('voyager::generic.no_results') }}
@endif
@endif
@elseif($options->type == 'belongsToMany')
@if(isset($view) && ($view == 'browse' || $view == 'read'))
@php
$relationshipData = (isset($data)) ? $data : $dataTypeContent;
$selected_values = isset($relationshipData) ? $relationshipData->belongsToMany($options->model, $options->pivot_table, $options->foreign_pivot_key ?? null, $options->related_pivot_key ?? null, $options->parent_key ?? null, $options->key)->get()->map(function ($item, $key) use ($options) {
return $item->{$options->label};
})->all() : array();
@endphp
@if($view == 'browse')
@php
$string_values = implode(", ", $selected_values);
if(mb_strlen($string_values) > 25){ $string_values = mb_substr($string_values, 0, 25) . '...'; }
@endphp
@if(empty($selected_values))
{{ __('voyager::generic.no_results') }}
@else
{{ $string_values }}
@endif
@else
@if(empty($selected_values))
{{ __('voyager::generic.no_results') }}
@else
@foreach($selected_values as $selected_value)
{{ $selected_value }}
@endforeach
@endif
@endif
@else
getKey())) data-id="{{$dataTypeContent->getKey()}}" @endif
data-method="{{ !is_null($dataTypeContent->getKey()) ? 'edit' : 'add' }}"
@if(isset($options->taggable) && $options->taggable === 'on')
data-route="{{ route('voyager.'.\Illuminate\Support\Str::slug($options->table).'.store') }}"
data-label="{{$options->label}}"
data-error-message="{{__('voyager::bread.error_tagging')}}"
@endif
@if($row->required == 1) required @endif
>
@php
$selected_values = isset($dataTypeContent) ? $dataTypeContent->belongsToMany($options->model, $options->pivot_table, $options->foreign_pivot_key ?? null, $options->related_pivot_key ?? null, $options->parent_key ?? null, $options->key)->get()->map(function ($item, $key) use ($options) {
return $item->{$options->key};
})->all() : array();
$relationshipOptions = app($options->model)->all();
$selected_values = old($relationshipField, $selected_values);
@endphp
@if(!$row->required)
{{__('voyager::generic.none')}}
@endif
@foreach($relationshipOptions as $relationshipOption)
{$options->key}, $selected_values)) selected="selected" @endif>{{ $relationshipOption->{$options->label} }}
@endforeach
@endif
@endif
@else
cannot make relationship because {{ $options->model }} does not exist.
@endif
@endif