Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LeachCreative's avatar

Whats the best way to handle adding a page title?

I'm wondering if anyone knows of a simple and clean way of adding page titles that are unique to a given page, without having to go into every spark controller?

Example: /spark/kiosk would be named "Kiosk Dashboard"

0 likes
2 replies
SyedAbuthahir's avatar
Level 4

If you have static pages you may store titles depend on route names in config folder and use it. last time i found this simple solution for my admin panel.

code example

config.php

return [
    'tasks.index'       =>  'All Tasks',
    'tasks.create'      =>  'New Task',
    'tasks.edit'        =>  'Edit Task',
    'tasks.show'        =>  'Task Details',
];

helpers.php

function getTitle() {
    $titles = config('titles');
    $currentRouteName = Route::currentRouteName();
    if( isset( $titles[$currentRouteName] ) ) {
        return $titles[$currentRouteName];
    }
    return '';
}

in layout file

<h1>{{ getTitle() }}</h1>
2 likes
LeachCreative's avatar

I love it, this is significantly better than any approach I came up with.

Please or to participate in this conversation.