BaseData

Introduction

In all our application we use a lot of key value lists. For example client types. The purpose of BaseData is to prevent development time waste, make all our list translatable and managable by our client.

How to use

BaseDataKeys can only be created by defining them in a module file Read how. BaseDataValues can be assigned to a key in the same place. When a key is editable_by_tenant the tenant can manage the values through the manage interface. When it is not possible to manage the values by a tenant he can still maintain translations for the values.

ERD

BaseDataKey

Relations

  • Values – relation to BaseDataValues
  • Properties – relation to morph property
  • Module – BelongsToModule trait

Traits

  • BelongsToModule
  • HasFactory
  • BelongsToDataType
  • HasPropertyValues
  • HasProperties

Scopes

  • scopeByKey()

Routes

Endpoint name permission
base-data-key/{$} show .show, .show.tenant, .manage, .manage.tenant
base-data-key index true
base-data-key/{$}/set set .manage or $model->editable_by_tenant == true AND base-data.value-manage.tenant
role/base-data baseData true

Services

getBaseQueryForRole()

Get a baseQuery

    /**
     * Get the base query for base data keys
     *
     * @return mixed
     */
    protected function getBaseQueryForRole()
    {
        return $this->getModel()
            ->whereIn('module_id', $this->moduleRepository->getForRole()->pluck('id'));
    }

getForTenantWithValues()

Get all BaseDataKeys with values for the current tenant dedicted from current role.

    /**
     * Get all base data for a tenant including values
     *
     * @return Collection
     */
    public function getForTenantWithValues(): Collection
    {
        $role = UserManager::get()->currentRole;

        <...>
    }

getForTenantWithValuesAndTranslations()

Same as method getForTenantWithValues but now also with the translations

    /**
     * Get all base data for a role including values and translations
     *
     * @return mixed
     */
    public function getForRoleWithValuesAndTranslations() 

BaseDataValue

Boot

If the config base-data.use_order === true The global scope is applied setting the default sort on the attribute order

This trait ensures the response cache is flushed on updates or deletes.

Relations

  • Key – relation to the BaseDataKey
  • Parent – relation to a parent BaseDataValue
  • Children – relation to children BaseDataValue
  • Properties – relation to morph property
  • Module – BelongsToModule trait

Traits

  • SoftDeletes
  • HasFactory
  • BelongsToTenant
  • TenantScopable
  • HasTranslations
  • HasPropertyValues

Scopes

  • scopeByKey()
  • scopeByValue()

Routes

Endpoint name permission
base-data-value/{$} show .show, .show.tenant
base-data-value/list list .show, .show.tenant
base-data-value/index index .show, .show.tenant
base-data-value create .manage, .manage.tenant
base-data-value/{$} update .manage, .manage.tenant. without possible to update translations
base-data-value/{$} destroy .mange OR ($model->editdable_by_tenant AND .manage.tenant)

Services

MarkasNotFromConfig()

Set a base data value as not_from_config now when the command blueprint:update is run this value will be skipped.

    /**
     * @param BaseDataValueContract $baseDataValue
     * @return void
     */
    public function markAsNotFromConfig(BaseDataValueContract $baseDataValue): void
    {
        $this->repository->update($baseDataValue, ['is_from_config' => false]);
    }