test custom field for account profile names select
This commit is contained in:
parent
427b5e8d55
commit
99bf2e33d4
|
|
@ -42,6 +42,19 @@ public function setup()
|
|||
], function ($value) { // if the filter is active
|
||||
$this->crud->addClause('where', 'state', $value);
|
||||
});
|
||||
|
||||
$this->crud->addFilter([
|
||||
'type' => 'date_range',
|
||||
'name' => 'from_to',
|
||||
'label' => 'Created at from-to'
|
||||
],
|
||||
false,
|
||||
function ($value) { // if the filter is active, apply these constraints
|
||||
$dates = json_decode($value);
|
||||
$this->crud->addClause('where', 'created_at', '>=', $dates->from);
|
||||
$this->crud->addClause('where', 'created_at', '<=', $dates->to . ' 23:59:59');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -55,21 +68,19 @@ protected function setupListOperation()
|
|||
$this->crud->addColumns([
|
||||
[
|
||||
'name' => 'profile',
|
||||
'type' => 'profile_name',
|
||||
'type' => 'account_profile_name',
|
||||
'label' => 'Account',
|
||||
],
|
||||
[
|
||||
'name' => 'state',
|
||||
'label' => 'State',
|
||||
'type' => 'select_from_array',
|
||||
'options' => [
|
||||
'new' => 'new',
|
||||
'applied' => 'applied',
|
||||
'approved' => 'approved',
|
||||
'archive' => 'archive'
|
||||
]
|
||||
'type' => 'badge',
|
||||
],
|
||||
[
|
||||
'name' => 'created_at',
|
||||
]
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -82,13 +93,25 @@ protected function setupCreateOperation()
|
|||
{
|
||||
CRUD::setValidation(ApplicationRequest::class);
|
||||
$this->crud->addFields([
|
||||
[
|
||||
'name' => 'account_id',
|
||||
'type' => 'select',
|
||||
'label' => 'Account',
|
||||
'entity' => 'account',
|
||||
'model' => "App\Models\Account",
|
||||
'attribute' => 'legalization_number'
|
||||
// [
|
||||
// 'name' => 'account_id',
|
||||
// 'type' => 'custom_select_account',
|
||||
// 'label' => 'Account',
|
||||
// 'entity' => 'account',
|
||||
// 'model' => "App\Models\Business",
|
||||
// 'model_2' => "App\Models\Company",
|
||||
// 'attribute_business_1' => 'name',
|
||||
// 'attribute_business_2' => 'surname',
|
||||
// 'attribute_2' => 'name'
|
||||
// ],
|
||||
[ // SelectMultiple = n-n relationship (with pivot table)
|
||||
'label' => "Account",
|
||||
'type' => 'custom_select_account',
|
||||
'name' => 'account_id', // the method that defines the relationship in your Model
|
||||
'entity' => 'account', // the method that defines the relationship in your Model
|
||||
'model' => "App\Models\Account", // foreign key model
|
||||
'attribute_1' => 'name', // foreign key attribute that is shown to user
|
||||
'attribute_2' => 'surname',
|
||||
],
|
||||
[
|
||||
'name' => 'state',
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Application extends Model
|
|||
// public $timestamps = false;
|
||||
// protected $guarded = ['id'];
|
||||
protected $fillable = [
|
||||
'account_id', 'status','state' ,'receipt_path','questionnaire_path'
|
||||
'account_id', 'status','state'
|
||||
];
|
||||
// protected $hidden = [];
|
||||
// protected $dates = [];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
@if ($entry->account->type == 'business')
|
||||
<p>{{ json_decode($entry->account->profile)->name ?? null }} {{ json_decode($entry->account->profile)->surname ?? null }}</p>
|
||||
@else
|
||||
<p>{{ json_decode($entry->account->profile)->name ?? null }}</p>
|
||||
@endif
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<h5>
|
||||
@if ($entry['state'] == 'new')
|
||||
<span class="badge badge-success">{{ $entry['state'] }}</span>
|
||||
@elseif($entry['state'] == 'applied')
|
||||
<span class="badge badge-info">{{ $entry['state'] }}</span>
|
||||
@elseif($entry['state'] == 'approved')
|
||||
<span class="badge badge-primary">{{ $entry['state'] }}</span>
|
||||
@elseif($entry['state'] == 'archive')
|
||||
<span class="badge badge-secondary">{{ $entry['state'] }}</span>
|
||||
@endif
|
||||
</h5>
|
||||
|
|
@ -3,5 +3,3 @@
|
|||
@else
|
||||
<p>{{ json_decode($entry->profile)->name ?? null }}</p>
|
||||
@endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
<!-- select -->
|
||||
@php
|
||||
$current_value = old(square_brackets_to_dots($field['name'])) ?? $field['value'] ?? $field['default'] ?? '';
|
||||
$entity_model = $crud->getRelationModel($field['entity'], - 1);
|
||||
$field['allows_null'] = $field['allows_null'] ?? $entity_model::isColumnNullable($field['name']);
|
||||
|
||||
//if it's part of a relationship here we have the full related model, we want the key.
|
||||
if (is_object($current_value) && is_subclass_of(get_class($current_value), 'Illuminate\Database\Eloquent\Model') ) {
|
||||
$current_value = $current_value->getKey();
|
||||
}
|
||||
|
||||
if (!isset($field['options'])) {
|
||||
$options = $field['model']::all();
|
||||
} else {
|
||||
$options = call_user_func($field['options'], $field['model']::query());
|
||||
}
|
||||
@endphp
|
||||
|
||||
@include('crud::fields.inc.wrapper_start')
|
||||
|
||||
<label>{!! $field['label'] !!}</label>
|
||||
@include('crud::fields.inc.translatable_icon')
|
||||
|
||||
<select
|
||||
name="{{ $field['name'] }}"
|
||||
@include('crud::fields.inc.attributes')
|
||||
>
|
||||
|
||||
@if ($field['allows_null'])
|
||||
<option value="">-</option>
|
||||
@endif
|
||||
|
||||
@if (count($options))
|
||||
|
||||
@foreach ($options as $connected_entity_entry)
|
||||
@if($connected_entity_entry->profile_id != null)
|
||||
@if($current_value == $connected_entity_entry->getKey())
|
||||
@if($connected_entity_entry->type == 'business')
|
||||
<option value="{{ $connected_entity_entry->getKey() }}" selected>{{ json_decode($connected_entity_entry->profile)->name }} {{ json_decode($connected_entity_entry->profile)->surname }}</option>
|
||||
@else
|
||||
<option value="{{ $connected_entity_entry->getKey() }}" selected>{{ json_decode($connected_entity_entry->profile)->name }}</option>
|
||||
@endif
|
||||
@else
|
||||
@if($connected_entity_entry->type == 'business')
|
||||
<option value="{{ $connected_entity_entry->getKey() }}">{{ json_decode($connected_entity_entry->profile)->name }} {{ json_decode($connected_entity_entry->profile)->surname }}</option>
|
||||
@else
|
||||
<option value="{{ $connected_entity_entry->getKey() }}">{{ json_decode($connected_entity_entry->profile)->name }}</option>
|
||||
@endif
|
||||
@endif
|
||||
@endif
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
|
||||
{{-- HINT --}}
|
||||
@if (isset($field['hint']))
|
||||
<p class="help-block">{!! $field['hint'] !!}</p>
|
||||
@endif
|
||||
|
||||
@include('crud::fields.inc.wrapper_end')
|
||||
Loading…
Reference in New Issue