carone/laravel-content
Composer 安装命令:
composer require carone/laravel-content
包简介
A light-weight CMS for Laravel projects
README 文档
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.
carone/laravel-content 适用场景与选型建议
carone/laravel-content 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「cms」 「laravel」 「content-management」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 carone/laravel-content 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 carone/laravel-content 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 carone/laravel-content 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
A PSR-7 compatible library for making CRUD API endpoints
Integrate with Snipcart.
Follow, Favourite, Bookmark, Like & Subscribe.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-29