In a Laravel 10 / Nova 4.27 app, I'm using a large editor with tabs ("eminiarts/nova-tabs": "^2.2"), and I need to show or hide one of the tabs based on the value of the other_shipping
field. Additionally, I want to set the header text and background color depending on the current status of the opened order.
Here's what I've tried:
public function fields(NovaRequest $request) {
$isEdit = ! empty($this->id);
\Log::info(' -13 fields $isEdit::');
\Log::info(json_encode($isEdit));
$editorTitle = 'Select status manually';
$headingBgColor = 'text-white-100';
$otherShipping= false;
$status = null;
if ($isEdit) {
$otherShipping = (bool) $this->other_shipping?->value;
$status = $this->status;
}
\Log::info(' -145 $status::');
\Log::info(json_encode($status));
$statusOptions = OrderStatusEnum::getStatusSelectionItems();
if ($isEdit) {
$headingBgColor = OrderStatusEnum::getStatusColors(hexValue: false)[$status->value];
$editorTitle = ' With "'.OrderStatusEnum::getLabel($this->status).'" status use buttons to change status';
}
return [
Heading::make('<p class="text-xl font-bold ' . $headingBgColor . '">' . $editorTitle . '</p>')->asHtml(),
Tabs::make('Order editor', [
Tab::make('Details', [
BelongsTo::make('Creator', 'creator', User::class),
// ...
]),
Tab::make('Billing Information', $this->getBillingFields())->showIf($otherShipping),
// ...
]),
];
However, this isn't working as expected. I need to check if the page is in index
, updating
, creating
, or detail
mode. How can I do this? Also, how can I access the model in updating
and detail
modes?
This is a loaded question! Start by fixing the isEdit
logic using the NovaRequest
to properly detect if you’re in update
or detail
mode:
$isEdit = $request->isUpdateOrUpdateAttachedRequest() || $request->isResourceDetailRequest();