abstract class ModuleController extends Controller (View source)

Traits

AuthorizesRequests
DispatchesJobs
ValidatesRequests

Properties

protected Application $app
protected Request $request
protected string $namespace
protected string $routePrefix
protected string $moduleName
protected string $modelName
protected string $modelTitle
protected ModuleRepository $repository
protected User $user
protected array $defaultIndexOptions

Options of the index view.

protected array $authorizableOptions

Options of the index view and the corresponding auth gates.

protected array $indexWith

Relations to eager load for the index view.

protected array $formWith

Relations to eager load for the form view.

protected array $formWithCount

Relation count to eager load for the form view.

protected array deprecated $filters

Additional filters for the index view.

$filterLinks

Additional links to display in the listing filter.

protected array deprecated $defaultOrders

Default orders for the index view for fields that are not part of the indexColumns.

protected int $perPage
protected string $titleColumnKey

Name of the index column to use as name column.

protected string $titleColumnLabel

Label of the index column to use as name column.

protected string $identifierColumnKey

Name of the index column to use as identifier column.

protected string $titleFormKey

Attribute to use as title in forms.

protected string $titleFormLabel

Label of the title field in forms.

protected string $featureField

Feature field name if the controller is using the feature route (defaults to "featured").

protected bool $submodule

Indicates if this module is edited through a parent module.

protected int|null $submoduleParentId
protected bool $disableEditor

Can be used in child classes to disable the content editor (full screen block editor).

protected array $indexOptions
protected array deprecated $indexColumns
protected array deprecated $browserColumns
protected string $permalinkBase
protected array deprecated $filtersDefaultOptions

Filters that are selected by default in the index view.

protected array deprecated $defaultFilters
protected string $viewPrefix
protected string $previewView
protected array $fieldsPermissions

List of permissions keyed by a request field. Can be used to prevent unauthorized field updates.

protected bool $enableDraftRevisions

Determines if draft revisions can be added on top of published content.

protected array $labels

Array of customizable label translation keys.

protected array|null $searchColumns

The columns to search for when using the search field.

protected array $defaultLabels

Default label translation keys that can be overridden in the labels array.

Methods

__construct(Application $app, Request $request)

No description

void
removeMiddleware(string $middleware)

Attempts to unset the given middleware.

array|null
getSubmitOptions(Model $item)

No description

array|null
getSubmitOptionsForDraftRevisions(Model $item)

No description

void
setUpController()

The setup method that is called when the controller is booted.

void
disableCreate()

Removes the "Create" button on the listing page.

void
disableEdit()

Disables table interaction and removes edit links.

void
disableSortable()

Disables the ability to sort the table by clicking table headers.

void
disablePublish()

Removes the publish/un-publish icon on the content listing.

void
disableBulkPublish()

Removes the "publish" option from the bulk operations.

void
disableRestore()

Removes "restore" from the list item dropdown on the "Trash" content list.

void
disableBulkRestore()

Removes the "Trash" quick filter.

void
disableForceDelete()

Removes the "delete" option from the "Trash" content list.

void
disableBulkForceDelete()

Removes "restore" from the bulk operations on the "Trash" content list.

void
disableDelete()

Removes the "delete" option from the content lists.

void
disableBulkDelete()

Removes the "delete" option from the bulk operations.

void
disablePermalink()

Removes the permalink from the create/edit screens.

void
disableEditor()

Disables the editor button.

void
disableBulkEdit()

Disables bulk operations.

void
disableIncludeScheduledInList()

Hides publish scheduling information from the content list.

void
enableSkipCreateModal()

Disables the create modal and directly forwards you to the full edit page.

void
enableFeature()

Allow to feature the content. This requires a 'featured' fillable boolean on the model.

void
enableBulkFeature()

Enables the "Feature" bulk operation.

void
enableDuplicate()

Enables the "Duplicate" option from the content lists.

void
enableReorder()

Allows to reorder the items, if this was setup on the model.

void
enableEditInModal()

Enables the function that content is edited in the create modal.

void
enableShowImage()

Shows the thumbnail of the content in the list.

void
setFeatureField(string $field)

Set the field to use for featuring content.

void
setSearchColumns(array $searchColumns)

Set the columns to search in.

void
setModuleName(string $moduleName)

Set the name of the module you are working with.

void
setPermalinkBase(string $permalinkBase)

The static permalink base to your module. Defaults to setModuleName when empty.

void
withoutLanguageInPermalink(bool $without = true)

No description

void
setTitleColumnKey(string $titleColumnKey)

Sets the field to use as title, defaults to title.

void
setTitleColumnLabel(string $titleColumnLabel)

Sets the label to use for title column, defaults to Title.

void
setTitleFormKey(string $titleFormKey)

Sets the field to use as title in forms, defaults to title.

void
setTitleFormLabel(string $titleFormLabel)

Sets the label to use for title field in forms, defaults to Title.

void
setModelName(string $modelName)

Usually not required, but in case customization is needed you can use this method to set the name of the model this controller acts on.

void
setResultsPerPage(int $resultsPerPage)

Sets the amount of results to show per page, defaults to 20.

void
eagerLoadListingRelations(array $relations)

Relations to eager load for the index view.

void
eagerLoadFormRelations(array $relations)

Relations to eager load for the form view.

void
eagerLoadFormRelationCounts(array $relations)

Relation count to eager load for the form view.

void
setBreadcrumbs(Breadcrumbs $breadcrumbs)

Set the breadcrumbs.

additionalBrowserTableColumns()

Similar to getBrowserTableColumns but these will be added on top of the default columns.

additionalIndexTableColumns()

Similar to getIndexTableColumns but these will be added on top of the default columns.

void
authorizeOption($option, $arguments = [])

Match an option name to a gate name if needed, then authorize it.

void
setMiddlewarePermission() deprecated

No description

string|int|null
getParentModuleIdFromRequest(Request $request)

No description

mixed
index(int|null $parentModuleId = null)

No description

getCreateForm()

No description

JsonResponse
browser()

No description

JsonResponse
store(int|null $parentModuleId = null)

No description

RedirectResponse
show($id, int|null $submoduleId = null)

No description

mixed
edit(TwillModelContract|int $id)

No description

View
create(int $parentModuleId = null)

No description

JsonResponse
update(TwillModelContract $id, int|null $submoduleId = null)

No description

void
performUpdate($item)

No description

View
preview(int $id)

No description

View
restoreRevision(int $id)

No description

JsonResponse
publish()

No description

JsonResponse
bulkPublish()

No description

JsonResponse
duplicate(TwillModelContract $id, int|null $submoduleId = null)

No description

JsonResponse
destroy(TwillModelContract $id, int|null $submoduleId = null)

No description

JsonResponse
bulkDelete()

No description

JsonResponse
forceDelete()

No description

JsonResponse
bulkForceDelete()

No description

JsonResponse
restore()

No description

JsonResponse
bulkRestore()

No description

JsonResponse
feature()

No description

JsonResponse
bulkFeature()

No description

JsonResponse
reorder()

No description

JsonResponse
tags()

No description

array
additionalTableActions()

No description

array
getIndexData(array $prependScope = [])

No description

array
indexData(Request $request)

No description

Collection
getIndexItems(array $scopes = [], bool $forcePagination = false)

No description

LengthAwarePaginator
transformIndexItems(LengthAwarePaginator $items)

No description

array
getIndexTableData(LengthAwarePaginator $items)

No description

indexItemData(TwillModelContract $item)

No description

null|int|string
getItemIdentifier(TwillModelContract $item)

No description

filters()

No description

quickFilters()

The quick filters to apply to the listing table.

array
getIndexUrls(string $moduleName, string $routePrefix)

No description

bool
getIndexOption(string $option, $item = null)

No description

array
getBrowserData(array $scopes = [])

No description

array
getBrowserTableData(LengthAwarePaginator $items, bool $forRepeater = false)

No description

Collection
getBrowserItems(array $scopes = [])

No description

array
getRequestFilters()

No description

void
applyFiltersDefaultOptions()

No description

array
orderScope()

No description

array
form(int|null $id, TwillModelContract|null $item = null)

No description

array
modalFormData(TwillModelContract $modelOrId)

No description

array
formData(Request $request)

No description

array
previewData(TwillModelContract $item)

No description

validateFormRequest()

No description

getFormRequestClass()

No description

string
getNamespace()

No description

string
getRoutePrefix()

No description

string
getModulePermalinkBase()

No description

string
getModelName()

No description

getRepository()

No description

string
getRepositoryClass($model)

No description

string|null
getViewPrefix()

No description

string
getModelTitle()

No description

string
getParentModuleForeignKey()

No description

string
getPermalinkBaseUrl()

No description

array
getLocalizedPermalinkBase()

No description

string
getPermalinkPrefix(string $baseUrl)

No description

string
getModuleRoute(int $id, string $action)

No description

bool
moduleHas(string $behavior)

No description

bool
titleIsTranslatable()

No description

void
setBackLink(string|null $back_link = null, array $params = [])

No description

string
getBackLink(string|null $fallback = null, array $params = [])

No description

string
getBackLinkSessionKey()

No description

RedirectResponse
redirectToForm(int $id, array $params = [])

No description

JsonResponse
respondWithSuccess(string $message)

No description

JsonResponse
respondWithRedirect(string $redirectUrl)

No description

JsonResponse
respondWithError(string $message)

No description

JsonResponse
respondWithJson(string $message, mixed $variant)

No description

getGroupUserMapping()

No description

void
fireEvent(array $input = [])

No description

getShowPermissionFieldset($item)

No description

Translator|string|array|null
getTransLabel(string $key, array $replace = [])

Get translation key from labels array and attemps to return a translated string.

getForm(TwillModelContract $model)

No description

getSideFieldsets(TwillModelContract $model)

No description

Details

__construct(Application $app, Request $request)

No description

Parameters

Application $app
Request $request

void removeMiddleware(string $middleware)

Attempts to unset the given middleware.

Parameters

string $middleware

Return Value

void

array|null getSubmitOptions(Model $item)

No description

Parameters

Model $item

Return Value

array|null

protected array|null getSubmitOptionsForDraftRevisions(Model $item)

No description

Parameters

Model $item

Return Value

array|null

protected void setUpController()

The setup method that is called when the controller is booted.

Return Value

void

protected void disableCreate()

Removes the "Create" button on the listing page.

Return Value

void

protected void disableEdit()

Disables table interaction and removes edit links.

Return Value

void

protected void disableSortable()

Disables the ability to sort the table by clicking table headers.

Return Value

void

protected void disablePublish()

Removes the publish/un-publish icon on the content listing.

Return Value

void

protected void disableBulkPublish()

Removes the "publish" option from the bulk operations.

Return Value

void

protected void disableRestore()

Removes "restore" from the list item dropdown on the "Trash" content list.

Return Value

void

protected void disableBulkRestore()

Removes the "Trash" quick filter.

Return Value

void

protected void disableForceDelete()

Removes the "delete" option from the "Trash" content list.

Return Value

void

protected void disableBulkForceDelete()

Removes "restore" from the bulk operations on the "Trash" content list.

Return Value

void

protected void disableDelete()

Removes the "delete" option from the content lists.

Return Value

void

protected void disableBulkDelete()

Removes the "delete" option from the bulk operations.

Return Value

void

Removes the permalink from the create/edit screens.

Return Value

void

protected void disableEditor()

Disables the editor button.

Return Value

void

protected void disableBulkEdit()

Disables bulk operations.

Return Value

void

protected void disableIncludeScheduledInList()

Hides publish scheduling information from the content list.

This does not affect custom table builders. Unless implemented.

Return Value

void

protected void enableSkipCreateModal()

Disables the create modal and directly forwards you to the full edit page.

Return Value

void

protected void enableFeature()

Allow to feature the content. This requires a 'featured' fillable boolean on the model.

If you want to use a different column you can use the setFeaturedField method.

Return Value

void

protected void enableBulkFeature()

Enables the "Feature" bulk operation.

Return Value

void

protected void enableDuplicate()

Enables the "Duplicate" option from the content lists.

Return Value

void

protected void enableReorder()

Allows to reorder the items, if this was setup on the model.

Return Value

void

protected void enableEditInModal()

Enables the function that content is edited in the create modal.

Return Value

void

protected void enableShowImage()

Shows the thumbnail of the content in the list.

Return Value

void

protected void setFeatureField(string $field)

Set the field to use for featuring content.

Parameters

string $field

Return Value

void

protected void setSearchColumns(array $searchColumns)

Set the columns to search in.

SearchColumns are automatically prefixes/suffixed with %.

Parameters

array $searchColumns

Return Value

void

protected void setModuleName(string $moduleName)

Set the name of the module you are working with.

Parameters

string $moduleName

Return Value

void

protected void setPermalinkBase(string $permalinkBase)

The static permalink base to your module. Defaults to setModuleName when empty.

Parameters

string $permalinkBase

Return Value

void

No description

Parameters

bool $without

Return Value

void

protected void setTitleColumnKey(string $titleColumnKey)

Sets the field to use as title, defaults to title.

Parameters

string $titleColumnKey

Return Value

void

protected void setTitleColumnLabel(string $titleColumnLabel)

Sets the label to use for title column, defaults to Title.

Parameters

string $titleColumnLabel

Return Value

void

protected void setTitleFormKey(string $titleFormKey)

Sets the field to use as title in forms, defaults to title.

Parameters

string $titleFormKey

Return Value

void

protected void setTitleFormLabel(string $titleFormLabel)

Sets the label to use for title field in forms, defaults to Title.

Parameters

string $titleFormLabel

Return Value

void

protected void setModelName(string $modelName)

Usually not required, but in case customization is needed you can use this method to set the name of the model this controller acts on.

Parameters

string $modelName

Return Value

void

protected void setResultsPerPage(int $resultsPerPage)

Sets the amount of results to show per page, defaults to 20.

Parameters

int $resultsPerPage

Return Value

void

protected void eagerLoadListingRelations(array $relations)

Relations to eager load for the index view.

Parameters

array $relations

Return Value

void

protected void eagerLoadFormRelations(array $relations)

Relations to eager load for the form view.

Add relationship used in multiselect and resource form fields.

Parameters

array $relations

Return Value

void

protected void eagerLoadFormRelationCounts(array $relations)

Relation count to eager load for the form view.

Parameters

array $relations

Return Value

void

protected void setBreadcrumbs(Breadcrumbs $breadcrumbs)

Set the breadcrumbs.

Parameters

Breadcrumbs $breadcrumbs

Return Value

void

protected TableColumns getBrowserTableColumns()

No description

Return Value

TableColumns

protected TableColumns getIndexTableColumns()

No description

Return Value

TableColumns

protected TableColumns additionalBrowserTableColumns()

Similar to getBrowserTableColumns but these will be added on top of the default columns.

Return Value

TableColumns

protected TableColumns additionalIndexTableColumns()

Similar to getIndexTableColumns but these will be added on top of the default columns.

Return Value

TableColumns

protected void authorizeOption($option, $arguments = [])

Match an option name to a gate name if needed, then authorize it.

Parameters

$option
$arguments

Return Value

void

protected void setMiddlewarePermission() deprecated

deprecated To be removed in Twill 3.0

No description

Return Value

void

protected string|int|null getParentModuleIdFromRequest(Request $request)

No description

Parameters

Request $request

Return Value

string|int|null

mixed index(int|null $parentModuleId = null)

No description

Parameters

int|null $parentModuleId

Return Value

mixed

Form getCreateForm()

No description

Return Value

Form

JsonResponse browser()

No description

Return Value

JsonResponse

JsonResponse store(int|null $parentModuleId = null)

No description

Parameters

int|null $parentModuleId

Return Value

JsonResponse

RedirectResponse show($id, int|null $submoduleId = null)

No description

Parameters

$id
int|null $submoduleId

Return Value

RedirectResponse

mixed edit(TwillModelContract|int $id)

No description

Parameters

TwillModelContract|int $id

Return Value

mixed

View create(int $parentModuleId = null)

No description

Parameters

int $parentModuleId

Return Value

View

JsonResponse update(TwillModelContract $id, int|null $submoduleId = null)

No description

Parameters

TwillModelContract $id
int|null $submoduleId

Return Value

JsonResponse

protected void performUpdate($item)

No description

Parameters

$item

Return Value

void

View preview(int $id)

No description

Parameters

int $id

Return Value

View

View restoreRevision(int $id)

No description

Parameters

int $id

Return Value

View

JsonResponse publish()

No description

Return Value

JsonResponse

JsonResponse bulkPublish()

No description

Return Value

JsonResponse

JsonResponse duplicate(TwillModelContract $id, int|null $submoduleId = null)

No description

Parameters

TwillModelContract $id
int|null $submoduleId

Return Value

JsonResponse

JsonResponse destroy(TwillModelContract $id, int|null $submoduleId = null)

No description

Parameters

TwillModelContract $id
int|null $submoduleId

Return Value

JsonResponse

JsonResponse bulkDelete()

No description

Return Value

JsonResponse

JsonResponse forceDelete()

No description

Return Value

JsonResponse

JsonResponse bulkForceDelete()

No description

Return Value

JsonResponse

JsonResponse restore()

No description

Return Value

JsonResponse

JsonResponse bulkRestore()

No description

Return Value

JsonResponse

JsonResponse feature()

No description

Return Value

JsonResponse

JsonResponse bulkFeature()

No description

Return Value

JsonResponse

JsonResponse reorder()

No description

Return Value

JsonResponse

JsonResponse tags()

No description

Return Value

JsonResponse

array additionalTableActions()

No description

Return Value

array

protected array getIndexData(array $prependScope = [])

No description

Parameters

array $prependScope

Return Value

array

protected array indexData(Request $request)

No description

Parameters

Request $request

Return Value

array

protected Collection getIndexItems(array $scopes = [], bool $forcePagination = false)

No description

Parameters

array $scopes
bool $forcePagination

Return Value

Collection

protected LengthAwarePaginator transformIndexItems(LengthAwarePaginator $items)

No description

Parameters

LengthAwarePaginator $items

Return Value

LengthAwarePaginator

protected array getIndexTableData(LengthAwarePaginator $items)

No description

Parameters

LengthAwarePaginator $items

Return Value

array

protected indexItemData(TwillModelContract $item)

No description

Parameters

TwillModelContract $item

protected null|int|string getItemIdentifier(TwillModelContract $item)

No description

Parameters

TwillModelContract $item

Return Value

null|int|string

TableFilters filters()

No description

Return Value

TableFilters

QuickFilters quickFilters()

The quick filters to apply to the listing table.

Return Value

QuickFilters

protected QuickFilters getDefaultQuickFilters()

No description

Return Value

QuickFilters

protected array getIndexUrls(string $moduleName, string $routePrefix)

No description

Parameters

string $moduleName
string $routePrefix

Return Value

array

protected bool getIndexOption(string $option, $item = null)

No description

Parameters

string $option
$item

Return Value

bool

protected array getBrowserData(array $scopes = [])

No description

Parameters

array $scopes

Return Value

array

protected array getBrowserTableData(LengthAwarePaginator $items, bool $forRepeater = false)

No description

Parameters

LengthAwarePaginator $items
bool $forRepeater

Return Value

array

protected Collection getBrowserItems(array $scopes = [])

No description

Parameters

array $scopes

Return Value

Collection

protected array getRequestFilters()

No description

Return Value

array

protected void applyFiltersDefaultOptions()

No description

Return Value

void

protected array orderScope()

No description

Return Value

array

protected array form(int|null $id, TwillModelContract|null $item = null)

No description

Parameters

int|null $id
TwillModelContract|null $item

Return Value

array

protected array modalFormData(TwillModelContract $modelOrId)

No description

Parameters

TwillModelContract $modelOrId

Return Value

array

protected array formData(Request $request)

No description

Parameters

Request $request

Return Value

array

protected array previewData(TwillModelContract $item)

No description

Parameters

TwillModelContract $item

Return Value

array

protected Request validateFormRequest()

No description

Return Value

Request

getFormRequestClass()

No description

protected string getNamespace()

No description

Return Value

string

protected string getRoutePrefix()

No description

Return Value

string

protected string getModulePermalinkBase()

No description

Return Value

string

protected string getModelName()

No description

Return Value

string

protected ModuleRepository getRepository()

No description

Return Value

ModuleRepository

protected string getRepositoryClass($model)

No description

Parameters

$model

Return Value

string

protected string|null getViewPrefix()

No description

Return Value

string|null

protected string getModelTitle()

No description

Return Value

string

protected string getParentModuleForeignKey()

No description

Return Value

string

string getPermalinkBaseUrl()

No description

Return Value

string

protected array getLocalizedPermalinkBase()

No description

Return Value

array

protected string getPermalinkPrefix(string $baseUrl)

No description

Parameters

string $baseUrl

Return Value

string

protected string getModuleRoute(int $id, string $action)

No description

Parameters

int $id
string $action

Return Value

string

protected bool moduleHas(string $behavior)

No description

Parameters

string $behavior

Return Value

bool

protected bool titleIsTranslatable()

No description

Return Value

bool

No description

Parameters

string|null $back_link
array $params

Return Value

void

No description

Parameters

string|null $fallback
array $params

Return Value

string

protected string getBackLinkSessionKey()

No description

Return Value

string

protected RedirectResponse redirectToForm(int $id, array $params = [])

No description

Parameters

int $id
array $params

Return Value

RedirectResponse

protected JsonResponse respondWithSuccess(string $message)

No description

Parameters

string $message

Return Value

JsonResponse

protected JsonResponse respondWithRedirect(string $redirectUrl)

No description

Parameters

string $redirectUrl

Return Value

JsonResponse

protected JsonResponse respondWithError(string $message)

No description

Parameters

string $message

Return Value

JsonResponse

protected JsonResponse respondWithJson(string $message, mixed $variant)

No description

Parameters

string $message
mixed $variant

Return Value

JsonResponse

protected getGroupUserMapping()

No description

protected void fireEvent(array $input = [])

No description

Parameters

array $input

Return Value

void

protected getShowPermissionFieldset($item)

No description

Parameters

$item

protected Translator|string|array|null getTransLabel(string $key, array $replace = [])

Get translation key from labels array and attemps to return a translated string.

Parameters

string $key
array $replace

Return Value

Translator|string|array|null

Form getForm(TwillModelContract $model)

No description

Parameters

TwillModelContract $model

Return Value

Form

Form getSideFieldsets(TwillModelContract $model)

No description

Parameters

TwillModelContract $model

Return Value

Form