carone / laravel-content
A light-weight CMS for Laravel projects
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/carone/laravel-content
Requires
- php: ^8.2
- illuminate/database: ^12.0
- illuminate/support: ^12.0
Requires (Dev)
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^11.0
README
A lightweight, developer-friendly content management package for Laravel applications. This is not a full-fledged CMS, but rather a simple solution for managing editable text and images directly in your views, perfect for quick content updates and typo fixes without deploying new code.
Features
- ๐ Simple Integration - Drop-in Blade components for editable content
- ๐ Text, Image & File Support - Manage text content, image paths, and file downloads
- ๐จ Built-in Visual Editor - Clean, modern interface for managing all your content
- ๐ Authentication Aware - Only show edit indicators to authenticated users
- โก Performance Optimized - Built-in caching support for fast content retrieval
- ๐ฏ Customizable - Extensive configuration options
- ๐ง Developer-Friendly - Minimal setup, maximum flexibility
Installation
Install the package via Composer:
composer require carone/laravel-content
Publish Configuration
Publish the configuration file to customize the package settings:
php artisan vendor:publish --provider="Carone\Content\CaroneContentServiceProvider" --tag="config"
This creates a config/content.php file where you can configure routes, middleware, caching, and default values.
Run Migrations
Publish and run the migrations to create the page_contents table:
php artisan vendor:publish --provider="Carone\Content\CaroneContentServiceProvider" --tag="migrations" php artisan migrate
Publish Views (Optional)
If you need to customize the component views:
php artisan vendor:publish --provider="Carone\Content\CaroneContentServiceProvider" --tag="views"
Usage
Basic Text Content
Use the editable-text component to create editable paragraphs:
<x-editable-text element="about-me-text" />
With custom classes and attributes:
<x-editable-text element="hero-title" class="text-4xl font-bold text-gray-900" />
Image Content
Use the editable-image component for editable images:
<x-editable-image element="company-logo" />
With custom attributes:
<x-editable-image element="hero-banner" class="w-full h-64 object-cover" alt="Hero Banner" />
File Downloads
Use the editable-file component for downloadable files:
<x-editable-file element="terms-and-conditions" />
With custom link text:
<x-editable-file element="user-manual" text="Download User Manual" class="btn btn-primary" />
By default, the component displays the filename as link text. Use the text attribute to customize it.
Content Editor
The package includes a beautiful, built-in visual editor for managing all your content.
Accessing the Editor
Navigate to the editor at:
https://yoursite.com/admin/content
(The prefix is configurable via CONTENT_ROUTE_PREFIX)
Editor Features
- ๐ Page List - View all pages with accurate content counts in the sidebar
- โ๏ธ Inline Editing - Edit content values directly with instant save
- โ Add Content - Add new content with dynamic component code snippets
- ๐ Copy to Clipboard - Copy component code with one click
- ๐๏ธ Delete Content - Remove individual content items
- ๐๏ธ Delete Pages - Remove entire pages with all their content
- ๐ Route Explorer - Discover and quick-add content for any application route
- ๐พ Auto-save - Changes are saved immediately with visual feedback
Dynamic Component Snippets
When adding new content, the editor shows you the exact Blade component code to add to your view, updated in real-time based on your inputs:
- Updates automatically as you type the element ID
- Changes when you select a different content type
- One-click copy to clipboard
- Example:
<x-editable-text element="hero-title" />
Delete Pages
Each page view includes a "Delete Page" button that removes the entire page and all its content items. This feature is also available when page loading fails, allowing you to clean up corrupt or invalid page entries.
Route Explorer
The editor includes a powerful "Route Explorer" feature that helps you quickly start managing content for any page in your application:
- Click "Discover Routes" at the bottom of the sidebar
- Browse all your application's web routes
- Click "Quick Add" next to any route to:
- Add the page to your sidebar
- Automatically open the "Add Content" modal
- Start creating content immediately
Pages added via Route Explorer are tracked in the frontend until you save your first content item, making it easy to explore without cluttering your database.
API Routes
The editor uses the following API endpoints (all under /api/admin/content by default):
GET /page/{pageId}- Fetch content for a specific pagePOST /content- Create or update contentDELETE /content/{id}- Delete a content itemDELETE /page/{pageId}- Delete an entire page with all contentGET /routes- Get all application routes
These routes automatically include the api middleware and can be further protected via your config.
Editor Access Control
By default, the editor is protected by the middleware defined in your config:
'middleware' => [ 'web', 'auth', ],
Add additional middleware for fine-grained control:
'middleware' => [ 'web', 'auth', 'can:manage-content', // Require specific permission ],
How It Works
- Define Content Areas - Add
<x-editable-text>,<x-editable-image>, or<x-editable-file>components in your views with unique element identifiers - View Your Pages - Content displays with default values when not yet defined
- Edit Content - Use the visual editor to update content or authenticated users see edit indicators on the frontend
- Store in Database - Content is stored per page and element combination
Content Retrieval
The package provides a get_content() helper function that retrieves all content for the current route:
$content = get_content(); $value = $content->get('about-me-text');
Content is automatically cached based on your configuration settings for optimal performance.
Console Commands
The package provides convenient Artisan commands for managing content:
Create Content
Interactively create new page content:
php artisan content:create
With options for automation:
php artisan content:create --page=home --element=hero-title --type=text --value="Welcome to our site"
Features:
- โ
Page ID validation (prevents invalid routes like
/) - โ Duplicate detection with update option
- โ Context-aware prompts based on content type
- โ Automatic cache clearing
- โ Shows component code to add to your view
List Content
Display all page content in a clean table:
php artisan content:list
Filter by page or type:
php artisan content:list --page=home
php artisan content:list --type=image
php artisan content:list --page=about --full # Show full values
Features:
- ๐ Grouped by page when showing all content
- ๐จ Color-coded content types
- โ๏ธ Automatic value truncation (use
--fullto disable)
Clear Content
Clear content from the database:
# Clear all content (with confirmation) php artisan content:clear # Clear specific page php artisan content:clear --page=home # Skip confirmation php artisan content:clear --force
Features:
- โ ๏ธ Confirmation prompts for safety
- ๐๏ธ Shows what will be deleted before clearing
- ๐งน Automatic cache clearing
Configuration
The config/content.php file provides extensive customization options:
Table Name
Customize the database table name:
'table_name' => env('CONTENT_TABLE_NAME', 'page_contents'),
Route Configuration
Configure the admin routes prefix:
'route_prefix' => env('CONTENT_ROUTE_PREFIX', 'admin/content'),
Middleware Protection
Protect your content management routes with middleware:
'middleware' => [ 'web', 'auth', // Add custom middleware like 'can:manage-content' ],
Default Values
Set default text, images, and files when content is not yet defined:
'defaults' => [ 'text' => env('CONTENT_DEFAULT_TEXT', '-- No content available --'), 'image' => env('CONTENT_DEFAULT_IMAGE', 'images/placeholder.png'), 'file' => env('CONTENT_DEFAULT_FILE', 'files/placeholder.pdf'), ],
Caching
Enable or disable caching and configure cache duration:
'cache' => [ 'enabled' => env('CONTENT_CACHE_ENABLED', true), 'ttl' => env('CONTENT_CACHE_TTL', 3600), // 1 hour 'key_prefix' => env('CONTENT_CACHE_PREFIX', 'laravel_content_'), ],
Environment Variables
You can set these in your .env file:
CONTENT_TABLE_NAME=page_contents CONTENT_ROUTE_PREFIX=admin/content CONTENT_DEFAULT_TEXT="Content coming soon..." CONTENT_DEFAULT_IMAGE=images/default.png CONTENT_DEFAULT_FILE=files/default.pdf CONTENT_CACHE_ENABLED=true CONTENT_CACHE_TTL=7200
Database Structure
The package creates a page_contents table with the following structure:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| page_id | string | Route name or page identifier |
| element_id | string | Unique element identifier |
| type | enum | Content type ('text', 'image', or 'file') |
Page ID Validation
Page IDs must follow these rules to ensure valid URLs:
- โ
Valid:
home,about,contact,blog/post-1,products/category - โ Invalid:
/(root route), paths with//(double slashes) - Must start and end with alphanumeric characters
- Can contain: letters, numbers, hyphens (
-), underscores (_), dots (.), forward slashes (/)
Note: The root route / cannot be used as a page ID. Use home or another identifier instead.
The editor's Route Explorer will automatically:
- Display a warning for routes with invalid page IDs
- Suggest alternatives (e.g.,
homefor/) - Disable the "Quick Add" button for invalid routes
API Routes
The package registers the following routes (under your configured prefix):
| Method | URI | Description |
|---|---|---|
| GET | /pages |
List all pages with content |
| POST | /pages |
Create/update page content |
| GET | /pages/{page} |
Show specific page content |
| PUT/PATCH | /pages/{page} |
Update page content |
| DELETE | /pages/{page} |
Delete page content |
Use Cases
Perfect for:
- โ Landing pages with editable hero sections
- โ About pages with team member bios and photos
- โ Contact information that needs occasional updates
- โ Feature descriptions and marketing copy
- โ Footer content and legal text
- โ Downloadable files (PDFs, documents, etc.)
- โ Quick typo fixes without redeployment
Not ideal for:
- โ Complex content hierarchies
- โ Multi-language content (no built-in i18n)
- โ Rich text editing with formatting
- โ Actual file uploads (only stores paths/URLs)
- โ Content versioning and workflows
Requirements
- PHP 8.2 or higher
- Laravel 12.0 or higher
Security
The package is designed to work with Laravel's built-in authentication. The editable indicators only show to authenticated users via auth()->check().
Important: Ensure you protect your content management routes with appropriate middleware to prevent unauthorized access.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
Author
Caron Emile
Email: emile.caron@constructiv.be
Support
For issues, questions, or suggestions, please open an issue on GitHub.
Note: This package provides the foundation for content management but does not include an admin UI for editing content. You'll need to implement your own editor interface or integrate with your existing admin panel.