Skip to main content

Overview

The Pages feature allows administrators to create custom static content pages with unique URLs. Perfect for About, Terms of Service, Privacy Policy, and other standalone pages outside the blog structure.

Database Structure

The pages table provides a simple yet flexible structure:
pages
  - id: bigint (primary key)
  - title: string
  - slug: string (unique)
  - content: text (nullable)
  - published: boolean (default: false)
  - created_at: timestamp
  - updated_at: timestamp
Reference: database/migrations/2025_05_18_185526_create_pages_table.php:14

Page Model

class Page extends Model
{
    protected $fillable = [
        'title',
        'slug',
        'content',
        'published'
    ];
}
Key Features:
  • Title: Display name of the page
  • Slug: URL-friendly identifier (e.g., about-us becomes /about-us)
  • Content: Rich text content for the page body
  • Published: Boolean flag to control visibility
Reference: app/Models/Page.php:7

User Workflows

Page Creation Workflow

  1. Access Page Builder
    • Navigate to admin panel
    • Go to Pages section
  2. Enter Page Details
    • Title: Enter descriptive page title
    • Slug: Create URL-friendly slug (must be unique)
      • Example: “About Us” → about-us
      • Example: “Privacy Policy” → privacy-policy
    • Content: Add page content using rich text editor
  3. Set Visibility
    • Draft Mode: Leave published as false
    • Public: Set published to true when ready to go live
  4. Save Page
    • Page becomes accessible at /{slug}
    • Only published pages visible to public
Note: Route implementation is currently commented out in routes/web.php:119-121

Edit Workflow

  1. Find Page
    • View list of all pages in admin panel
    • Search by title or slug
  2. Update Content
    • Modify title, slug, or content
    • Change publication status
  3. Slug Considerations
    • Changing slug will change the URL
    • May break existing links
    • Consider implementing redirects for old URLs
  4. Save Changes
    • Updated content immediately reflects on frontend
    • Version history not tracked (consider adding revisions)

Publication Controls

Publishing a Page:
  • Set published to true
  • Page becomes publicly accessible
  • Appears in site navigation (if configured)
Unpublishing a Page:
  • Set published to false
  • Page returns 404 to public visitors
  • Still accessible in admin panel
  • Useful for temporary removal without deletion
Use Cases:
  • Seasonal content (hide during off-season)
  • Work-in-progress pages
  • Legal pages requiring updates

Frontend Display

Dynamic Page Routing

Pages are displayed using dynamic slug-based routing:
public function show($slug)
{
    $page = Page::where('slug', $slug)
        ->where('published', true)
        ->firstOrFail();
        
    return view('pages.show', compact('page'));
}
Key Features:
  • Published Check: Only shows pages with published = true
  • 404 Handling: Returns 404 if page not found or unpublished
  • SEO-Friendly URLs: Clean URLs without /page/ prefix
Reference: app/Http/Controllers/PageController.php:10

Example URLs

About Page

Slug: about-us
URL: https://yoursite.com/about-us
Displays company information, team details, mission statement.

Privacy Policy

Slug: privacy-policy
URL: https://yoursite.com/privacy-policy
Displays legal privacy information and data handling practices.

Terms of Service

Slug: terms-of-service
URL: https://yoursite.com/terms-of-service
Displays user agreement and service terms.

Contact

Slug: contact
URL: https://yoursite.com/contact
Contact form and business information.

Implementation Notes

The dynamic page route is currently commented out in the routes file:
// routes/web.php:119-121
// Route::get('/{slug}', [PageController::class, 'show'])
//     ->where('slug', '[A-Za-z0-9\-]+') 
//     ->name('page.show');
To enable custom pages, uncomment this route. Place it at the end of your routes file to prevent conflicts with other routes.

Route Constraints

The page route includes a regex constraint:
->where('slug', '[A-Za-z0-9\-]+')
Allowed Characters:
  • Lowercase letters (a-z)
  • Uppercase letters (A-Z)
  • Numbers (0-9)
  • Hyphens (-)
Not Allowed:
  • Spaces
  • Special characters (@, #, $, etc.)
  • Underscores
  • Slashes

Best Practices

Slug Guidelines:
  • Keep slugs short and descriptive
  • Use hyphens to separate words
  • Avoid numbers unless necessary
  • Make slugs permanent (don’t change after publication)
Content Guidelines:
  • Use proper heading hierarchy (H1 → H2 → H3)
  • Include meta descriptions
  • Optimize for keywords
  • Add internal links to other pages

Common Use Cases

Static Content

  • About Us
  • Company History
  • Team Bios
  • Mission & Values

Legal Pages

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • Disclaimer

Marketing

  • Landing Pages
  • Product Features
  • Pricing
  • Case Studies

Support

  • FAQ
  • Help Center
  • Documentation
  • Contact Info

Extending Pages

Extend Page Functionality

Add custom fields to pages for enhanced features:1. Create Migration:
Schema::table('pages', function (Blueprint $table) {
    $table->string('meta_description')->nullable();
    $table->string('meta_keywords')->nullable();
    $table->string('template')->default('default');
    $table->integer('view_count')->default(0);
});
2. Update Model:
protected $fillable = [
    'title', 'slug', 'content', 'published',
    'meta_description', 'meta_keywords', 'template'
];
3. Use in Views:
<meta name="description" content="{{ $page->meta_description }}">

Multiple Template Support

Implement different layouts for different page types:Controller Logic:
public function show($slug)
{
    $page = Page::where('slug', $slug)
        ->where('published', true)
        ->firstOrFail();
    
    $template = $page->template ?? 'default';
    
    return view("pages.templates.{$template}", compact('page'));
}
Template Options:
  • default - Standard page layout
  • wide - Full-width layout
  • landing - Marketing landing page
  • sidebar - Two-column with sidebar

Key Routes

MethodURIActionDescription
GET/{slug}PageController@showDisplay page by slug
Note: This route is currently commented out. See Implementation Notes above. Reference: routes/web.php:119-121

Build docs developers (and LLMs) love