litepie/layout
Composer 安装命令:
composer require litepie/layout
包简介
A flexible, component-based layout organizer for Laravel with infinite composition of different section types
关键字:
README 文档
README
A powerful and flexible Laravel package for building dynamic, data-driven layouts with support for nested sections, components, authorization, caching, and responsive behavior.
Table of Contents
Overview
Litepie Layout Builder provides a fluent, declarative API for creating complex UI layouts in Laravel applications. It separates layout structure from presentation logic, making it easy to build reusable, maintainable, and testable UI components.
Key Features
- Declarative Layout API - Build layouts using a fluent, chainable interface
- Sections & Components - Clear separation between containers (Sections) and content (Components)
- Named Section Slots - Organize content in header, body, footer, and custom slots
- Authorization - Built-in permission and role-based access control
- Data Binding - Automatic data loading from multiple sources (API, database, closures)
- Responsive Design - Device-specific layout configurations
- Caching - Performance optimization with flexible cache strategies
- Events - Lifecycle hooks for before/after rendering
- Validation - Input validation with Laravel validator integration
- Internationalization - Multi-language support with automatic translation
- Export/Import - JSON serialization for layout persistence
Installation
Requirements
- PHP 8.1 or higher
- Laravel 10.x or 11.x
Install via Composer
composer require litepie/layout
Publish Configuration (Optional)
php artisan vendor:publish --provider="Litepie\Layout\LayoutServiceProvider"
This creates config/layout.php where you can customize default behavior.
Quick Start
Basic Example
use Litepie\Layout\Facades\Layout; // Create a simple card layout $layout = Layout::create('dashboard') ->section('main', function ($section) { $section->card('user-stats') ->title('User Statistics') ->dataUrl('/api/stats') ->addField('total_users', 'Total Users') ->addField('active_users', 'Active Today') ->addField('new_registrations', 'New This Month'); }); // Render using the layout response macro (recommended) return response()->layout($layout->cache(true, 3600)); // Or render to array manually return response()->json($layout->render());
Creating a Form
use Litepie\Layout\Facades\Layout; $layout = Layout::create('user-form') ->section('main', function ($section) { $section->form('user-form') ->action('/users') ->method('POST') ->addField('name', 'text', 'Full Name') ->addField('email', 'email', 'Email Address') ->addField('role', 'select', 'Role', ['options' => ['admin', 'user', 'guest']]) ->addButton('submit', 'Save User', 'primary'); }); return $layout->render();
Multi-Section Layout
use Litepie\Layout\Facades\Layout; $layout = Layout::create('dashboard') ->section('header', function ($section) { $section->breadcrumb('navigation') ->addItem('Home', '/') ->addItem('Dashboard', '/dashboard'); }) ->section('main', function ($section) { // Grid layout with multiple cards $section->grid('stats-grid') ->columns(3) ->addComponent( $section->card('revenue') ->title('Revenue') ->dataUrl('/api/revenue') ) ->addComponent( $section->card('orders') ->title('Orders') ->dataUrl('/api/orders') ) ->addComponent( $section->card('customers') ->title('Customers') ->dataUrl('/api/customers') ); }) ->section('footer', function ($section) { $section->text('copyright') ->content('© 2025 Your Company'); }); return $layout->render();
Core Concepts
Sections vs Components
The layout system has two fundamental building blocks:
Sections (Containers)
Sections are containers that organize other elements using named slots (header, body, footer, sidebar, etc.). They define structure but don't render content themselves.
Available Sections:
HeaderSection- Page headers with navigationLayoutSection- Main layout containersGridSection- Responsive grid layoutsTabsSection- Tabbed interfacesAccordionSection- Collapsible panelsWizardSection- Multi-step workflowsScrollSpySection- Scroll-based navigation
Components (Content)
Components are leaf nodes that render actual content. They cannot contain other elements.
Available Components:
FormComponent- Forms with fields and validationCardComponent- Content cardsTableComponent- Data tables with sorting/filteringListComponent- Lists (ordered, unordered, definitions)AlertComponent- Notifications and messagesBadgeComponent- Labels and tagsModalComponent- Dialogs and popupsChartComponent- Data visualizationsTextComponent- Rich text contentCodeComponent- Syntax-highlighted code blocksMediaComponent- Images, videos, galleriesStatsComponent- Statistics displaysTimelineComponent- Event timelinesCommentComponent- Comment threadsBreadcrumbComponent- Navigation breadcrumbsDocumentComponent- Document managementCustomComponent- Custom HTML/JSON content
Section Slots
Sections organize content using named slots:
$layout->section('main', function ($section) { // Add to 'header' slot $section->section('header')->text('title')->content('Dashboard'); // Add to 'body' slot (default) $section->card('main-content')->title('Content'); // Add to 'footer' slot $section->section('footer')->text('info')->content('Last updated: Today'); });
Nesting Rules
- ✅ Sections can contain Sections - Create nested layouts
- ✅ Sections can contain Components - Add content to containers
- ❌ Components cannot contain anything - They are leaf nodes
Architecture
High-Level Structure
Layout (Root Container)
├── Section (e.g., "header")
│ ├── Component (e.g., Breadcrumb)
│ └── Component (e.g., Alert)
├── Section (e.g., "main")
│ ├── Section (e.g., Grid)
│ │ ├── Component (e.g., Card)
│ │ ├── Component (e.g., Table)
│ │ └── Component (e.g., Chart)
│ └── Section (e.g., Tabs)
│ ├── Tab 1 → Component (Form)
│ └── Tab 2 → Component (List)
└── Section (e.g., "footer")
└── Component (e.g., Text)
Class Hierarchy
BaseSection (Container with slots)
├── HeaderSection
├── LayoutSection
├── GridSection
├── TabsSection
├── AccordionSection
├── WizardSection
└── ScrollSpySection
BaseComponent (Content leaf node)
├── FormComponent
├── CardComponent
├── TableComponent
├── ListComponent
├── AlertComponent
├── BadgeComponent
├── ModalComponent
├── ChartComponent
├── TextComponent
├── MediaComponent
├── StatsComponent
├── TimelineComponent
├── CommentComponent
├── BreadcrumbComponent
├── DocumentComponent
├── AvatarComponent
├── DividerComponent
└── CustomComponent (extensible for custom components)
Features
1. Data Binding
Load data from multiple sources:
// From API endpoint $section->card('api-data') ->dataUrl('/api/stats') ->dataParams(['filter' => 'active']); // From database $section->table('users') ->dataSource('users') ->dataTransform(function ($query) { return $query->where('active', true)->orderBy('created_at', 'desc'); }); // From closure $section->card('dynamic') ->dataSource(function () { return [ 'total' => User::count(), 'active' => User::where('active', true)->count(), ]; });
2. Authorization
Control visibility with permissions and roles:
$section->card('admin-panel') ->permissions(['manage-users', 'view-logs']) ->canSee(function ($user) { return $user->isAdmin(); }); // Resolve authorization for current user $layout->resolveAuthorization(auth()->user());
3. Responsive Design
Device-specific configurations:
$section->grid('responsive-grid') ->columns(4) ->setDeviceConfig('mobile', ['columns' => 1]) ->setDeviceConfig('tablet', ['columns' => 2]);
4. Caching
Improve performance with automatic caching:
$layout->cache() ->ttl(3600) ->key('dashboard-layout') ->tags(['layouts', 'dashboard']);
5. Events
Hook into the rendering lifecycle:
$layout->beforeRender(function ($layout) { Log::info('Rendering layout: ' . $layout->getName()); }); $layout->afterRender(function ($layout, $output) { Log::info('Rendered layout with ' . count($output) . ' sections'); });
6. Conditional Logic
Show/hide elements based on conditions:
$section->card('premium-features') ->condition('user.subscription.status == "active"') ->condition('user.subscription.plan == "premium"');
7. Validation
Validate form inputs:
$section->form('user-form') ->validationRules([ 'name' => 'required|min:3|max:255', 'email' => 'required|email|unique:users', 'age' => 'required|integer|min:18', ]);
8. Internationalization
Multi-language support:
$section->card('welcome') ->title('layout.welcome.title') // Translatable key ->translate(); // Enable translation // Or translate specific fields $section->form('contact') ->translateField('submit_button', 'forms.submit');
Documentation
Backend (PHP/Laravel)
- Architecture Guide - Detailed architecture and design patterns
- API Reference - Complete API documentation for all sections and components
- Examples - Comprehensive usage examples and patterns
- Custom Components Guide - Create project-specific components
- Complete Guide - Comprehensive documentation
Frontend Implementations
- Frontend Overview - Overview of all frontend implementations
- React/Next.js - ✅ Complete TypeScript implementation with Tailwind CSS
- Vue.js - 📋 Planned implementation
- Flutter - 📋 Planned implementation
Code Examples (PHP)
- Basic Usage - Simple layout examples
- Dashboard Example - Complete dashboard with stats and charts
- Avatar Component - User avatar display examples
- Divider Component - Visual separator examples
- Custom Components - Creating custom components
Testing
Run the test suite:
composer test
Run with coverage:
composer test:coverage
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security-related issues, please email security@litepie.com instead of using the issue tracker.
License
The MIT License (MIT). Please see LICENSE for more information.
Credits
- Litepie Team
- All Contributors
Support
- Documentation: https://litepie.com/docs/layout
- Issues: GitHub Issues
- Email: support@litepie.com
litepie/layout 适用场景与选型建议
litepie/layout 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「authorization」 「form」 「components」 「Flexible」 「layout」 「grid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 litepie/layout 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 litepie/layout 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 litepie/layout 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Web Font Loader gives you added control when using linked fonts via @font-face.
A Laravel Filament Forms slug field.
Laravel JWT auth service package
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-10