esanj / public-pages
Public pages for Laravel apps including home and error pages.
Installs: 94
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/esanj/public-pages
Requires
- php: ^8.2
- illuminate/support: ^12.0
README
esanj/public-pages is a Laravel package providing clean and customizable public-facing pages such as error views (404,
500, 403, etc.), along with localized messages and frontend assets (CSS/JS/images).
Built for maintainability and full flexibility, this package integrates quickly into any Laravel 10+ or 12 project with a few commands.
β¨ Features
- β Pre-designed error templates (404, 500, 403, etc.)
- π Includes public assets (CSS, iconsβ¦)
- π Supports multi-language via Laravel's lang system
- π¨ Full ability to customize views, assets, config & messages
- β‘ Works out-of-the-box with Blade or Livewire
- π§Ό Clean UI with minimal setup time
π¦ Installation
1οΈβ£ Install via Composer:
composer require esanj/public-pages
2οΈβ£ Then publish the views and assets with:
php artisan publicpages:install
This command will publish:
Blade views β resources/views/vendor/publicpages/
Assets β public/assets/vendor/publicpages/
Youβre ready to go!
π File Structure (after install)
resources/
βββ views/
β βββ vendor/publicpages/home.blade.php
β βββ errors/
β βββ 404.blade.php
β βββ 500.blade.php
β βββ ...
public/
βββ assets/
βββ vendor/
βββ public-pages/
βββ style.css
βββ background.png
π§© Commands Overview
β¬οΈ Installs views and assets (required)
php artisan publicpages:install
π Publishes ONLY views + assets
php artisan publicpages:publish-views
π Publishes language/translation files
php artisan publicpages:publish-lang
βοΈ Publishes config file
php artisan publicpages:publish-config
You can rerun them anytime using --force.
π Localization
This package supports multiple languages.
To publish translation files:
php artisan publicpages:publish-lang
This will create:
π /lang/*/publicpages.php
Sample structure:
return [ 'errors' => [ '404' => [ 'title' => 'Page not found', 'message' => 'The page youβre looking for does not exist.', ], '500' => [ 'title' => 'Internal Server Error', 'message' => 'Something went wrong. Please try again later.', ], // Add more codes... ] ];
You can create files for other locales (e.g. fa, es, etc.) as needed.
β Add New Error Page
To support a new status code like 505 (HTTP Version Not Supported):
1οΈβ£ Add entry in your lang file:
'505' => [ 'title' => 'HTTP Version Not Supported', 'message' => 'The server does not support the HTTP protocol version used in the request.', ],
2οΈβ£ Then create a new blade file:
resources/views/errors/505.blade.php
This file can extend the base layout and use the dynamic error message like so:
@extends('errors::layout') @php $code = 505; @endphp
π₯ Publishing Config
To publish the configuration file:
php artisan publicpages:publish-config
This creates:
config/publicpages.php
βοΈ Available Options
π·οΈ Application Name
Controls the app name displayed on public and error pages.
'app_name' => env('APP_NAME', 'eSanj'),
π‘ Tip: Override via .env:
APP_NAME="My Custom App"
π Home Page Configuration
Controls whether the package registers a home route and where it points.
'home' => [ 'enabled' => env('PUBLIC_PAGES_HOME_ENABLED', true), // Enable/disable the home route registration 'path' => env('PUBLIC_PAGES_HOME_PATH', '/'), // URI path for the home page 'view' => 'publicpages::home', // Blade view to render ],
π§ Example: Disable home route
In .env:
PUBLIC_PAGES_HOME_ENABLED=false
π§ Example: Change home path to:
- /welcome
In .env:
PUBLIC_PAGES_HOME_PATH=/welcome
Or directly in config:
'path' => '/welcome',
π§ Example: Use custom view
'view' => 'pages.custom-home',
π£οΈ Route Middleware
Define which middleware groups apply to public pages routes.
'routes' => [ 'middleware' => ['web'], ],
π§ Example: Add guest middleware
'middleware' => ['web', 'guest'],
β Error Pages Configuration
Controls whether custom error pages are used and which layout they extend.
'errors' => [ 'enabled' => env('PUBLIC_PAGES_ERRORS_ENABLED', true), 'layout' => 'errors.layout', ],
Options:
Key Type Default Description enabled bool true Enable/disable custom error pages layout string 'errors.layout' Base Blade layout for error views
π§ Example: Disable custom error pages
In .env:
PUBLIC_PAGES_ERRORS_ENABLED=false
π§ Example: Use custom error layout
'layout' => 'layouts.error-base',
Then create resources/views/layouts/error-base.blade.php with your custom structure.
π Full Config Reference
Hereβs the complete default config structure:
<?php return [ // App name shown on pages 'app_name' => env('APP_NAME', 'eSanj'), // Home page settings 'home' => [ 'enabled' => env('PUBLIC_PAGES_HOME_ENABLED', true), 'path' => env('PUBLIC_PAGES_HOME_PATH', '/'), 'view' => 'publicpages::home', ], // Route configuration 'routes' => [ 'middleware' => ['web'], ], // Error pages settings 'errors' => [ 'enabled' => env('PUBLIC_PAGES_ERRORS_ENABLED', true), 'layout' => 'errors.layout', ], ];
π― Common Use Cases
β Disable home route (using your own routes)
PUBLIC_PAGES_HOME_ENABLED=false
β Change home page path
PUBLIC_PAGES_HOME_PATH=/start
β Use Laravelβs default error pages
PUBLIC_PAGES_ERRORS_ENABLED=false
β Customize app name
APP_NAME="My Startup"
β
Apply auth middleware to home route
In config/esanj/publicpages.php:
'routes' => [ 'middleware' => ['web', 'auth'], ],
π Reverting to Defaults
If you want to reset configuration:
Delete config/esanj/publicpages.php
Clear config cache:
php artisan config:clear
The package will use built-in defaults automatically.
π¦ Publishing Summary
You can always run a specific tag manually:
Tag Includes
public-pages-views π¨ Views only
public-pages-assets π§© Public assets only
public-pages-lang π Language files
public-pages-config βοΈ Configuration file
Example:
php artisan vendor:publish --tag=public-pages-views
π License
MIT Β© 2025 β Esanj Team