kminek / laravel-title
Probably the easiest way to add dynamic HTML title to Laravel app
Installs: 76
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kminek/laravel-title
Requires
- php: >=8.2.0
- illuminate/container: 11.*|12.*
- illuminate/support: 11.*|12.*
Requires (Dev)
- laravel/pint: 1.20.0
This package is auto-updated.
Last update: 2025-10-24 22:42:52 UTC
README
Probably the easiest way to add dynamic HTML title to Laravel app
Installation
Run the following command from your terminal:
composer require kminek/laravel-title
or add this to require section in your composer.json file:
"kminek/laravel-title": "^1.0"
then run composer update
Version compatibility
| Laravel | laravel-title |
|---|---|
| 11.x / 12.x | 1.x |
Usage
Modify your layout view (for example resources/views/layouts/app.blade.php):
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>{{ title() }}</title> </head> <body> <main> @yield('content') </main> </body> </html>
Modify your controller action view (for example resources/views/auth/register.blade.php):
@extends('layouts.app')
@title('Register')
@section('content')
<h1>
Register
</h1>
...
@endsection
Advanced usage
Change default separator (|):
<title>{{ title()->separator(' - ') }}</title>
Change default text (config('app.name')):
<title>{{ title()->default('AppName') }}</title>
Set a description which is displayed when no title is set inside controller action view:
<title>{{ title()->default('AppName')->description('This app will blow your mind!') }}</title>
You are not required to use @title() Blade directive, you can call
library directly which opens more possibilities:
@extends('layouts.app')
@php(title()->append('Register')) {{-- append (same behaviour as Blade directive) --}}
@php(title()->prepend('Register')) {{-- prepend --}}
@php(title()->set('Register')) {{-- replace whole stack --}}
@section('content')
<h1>
Register
</h1>
...
@endsection
You can have multiple title "stacks" under different keys. Default stack is using "default" as a key, but you are free to create new ones:
<title>{{ title('homepage') }}</title>
and later in Blade view:
@php(title('homepage')->append('Register'))