Customizing the header on different record pages

How can I know that am on view record or edit record page so that I customize the heading of the page
No description
18 Replies
codeartisan
codeartisanOP10mo ago
For instance am on the edit page but I still have the title of create new child Yet i wanted it to be edit child
toeknee
toeknee10mo ago
Where is your code for create form? You will just need the context added in
Tieme
Tieme10mo ago
Like fn ($context): int => $context === 'edit'
codeartisan
codeartisanOP10mo ago
return $form
->schema([
Forms\Components\Section::make('Create a new child')
->description('Add a new child to the system.')
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(255)
->label("First Name"),
Forms\Components\TextInput::make('middle_name')
->label("Middle Name")
->maxLength(255),
Forms\Components\TextInput::make('second_name')
->required()
->maxLength(255)
->label("Second Name"),
Select::make('gender')
->options([
'Male' => 'Male',
'Female' => 'Female',
])
->required()
->label("Gender"),
DatePicker::make('date_of_birth')
->label("Date Of Birth")
->required()
->label("Date of Birth"),



]);
return $form
->schema([
Forms\Components\Section::make('Create a new child')
->description('Add a new child to the system.')
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(255)
->label("First Name"),
Forms\Components\TextInput::make('middle_name')
->label("Middle Name")
->maxLength(255),
Forms\Components\TextInput::make('second_name')
->required()
->maxLength(255)
->label("Second Name"),
Select::make('gender')
->options([
'Male' => 'Male',
'Female' => 'Female',
])
->required()
->label("Gender"),
DatePicker::make('date_of_birth')
->label("Date Of Birth")
->required()
->label("Date of Birth"),



]);
where do I add that context
toeknee
toeknee10mo ago
return $form
->schema([
Forms\Components\Section::make(fn($context) => $context === 'edit' ? 'Editing Child' : 'Creating a new Child')
->description('Add a new child to the system.')
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(255)
->label("First Name"),
Forms\Components\TextInput::make('middle_name')
->label("Middle Name")
->maxLength(255),
Forms\Components\TextInput::make('second_name')
->required()
->maxLength(255)
->label("Second Name"),
Select::make('gender')
->options([
'Male' => 'Male',
'Female' => 'Female',
])
->required()
->label("Gender"),
DatePicker::make('date_of_birth')
->label("Date Of Birth")
->required()
->label("Date of Birth"),



]);
return $form
->schema([
Forms\Components\Section::make(fn($context) => $context === 'edit' ? 'Editing Child' : 'Creating a new Child')
->description('Add a new child to the system.')
->schema([
Forms\Components\TextInput::make('first_name')
->required()
->maxLength(255)
->label("First Name"),
Forms\Components\TextInput::make('middle_name')
->label("Middle Name")
->maxLength(255),
Forms\Components\TextInput::make('second_name')
->required()
->maxLength(255)
->label("Second Name"),
Select::make('gender')
->options([
'Male' => 'Male',
'Female' => 'Female',
])
->required()
->label("Gender"),
DatePicker::make('date_of_birth')
->label("Date Of Birth")
->required()
->label("Date of Birth"),



]);
DariusIII
DariusIII10mo ago
You need to override the
getTitle()
getTitle()
function on resource page Or as above, as @toeknee pasted, if it is based on context.
codeartisan
codeartisanOP10mo ago
then what of view also
codeartisan
codeartisanOP10mo ago
I have fixed it but am how can i make the gender show on the view page
No description
toeknee
toeknee10mo ago
Are you sure they have a gender on the edit as in your screenshot it's not selected.
codeartisan
codeartisanOP10mo ago
I select gender on creation of a child and on the list page I have it as well but on show and edit the selected gender does not appear
No description
codeartisan
codeartisanOP10mo ago
I think there is something i need to do probably before the viiew or edit pages are rendered
toeknee
toeknee10mo ago
You are not casting it to an array as per the select docs I suspect ensure your model has protected $casts =['gender' => array];
codeartisan
codeartisanOP10mo ago
I have added it and created another child but same issue
toeknee
toeknee10mo ago
is it stored in the database are you sure gender is fillable on the model
codeartisan
codeartisanOP10mo ago
protected $casts = [
'story' => 'array',
'hobby' => 'array',
'gender' => 'array',
];
protected $casts = [
'story' => 'array',
'hobby' => 'array',
'gender' => 'array',
];
I had added gender in the $hidden i think it affects those pages now it comes
codeartisan
codeartisanOP10mo ago
How do I shift the save changes and cancel button to the right
No description
toeknee
toeknee10mo ago
Hidden means the values stay hidden... so yep that'll do it.
codeartisan
codeartisanOP10mo ago
Yeah now it shows thank you so much let me search how to shift those buttons to the right
Want results from more Discord servers?
Add your server