laravel-cortex/cortex
Composer 安装命令:
composer require laravel-cortex/cortex
包简介
Zero-Config Enterprise Agent for Laravel
README 文档
README
The missing brain for your Laravel application.
Give your users a powerful "Cmd+K" interface to navigate, search, and execute complex actions using natural language.
✨ Features at a Glance
| Feature | Description |
|---|---|
| 🔍 Global Smart Search | Instantly find any Route, Model, or Resource in your app. |
| 🤖 AI Natural Language | Type "Delete inactive users" or "Show high value orders" and let AI handle it. |
| 🏢 Multi-Tenant Switcher | Switch organizations instantly without complex UI. Built-in session handling. |
| ⚡ Stack Agnostic | Drop-in support for Livewire, Vanilla JS (Blade), and Headless (Next.js). |
| 🛡️ Permission Aware | Automatically hides actions user isn't authorized for (can, auth middleware). |
| ⚙️ Developer Mode | Toggle between client (friendly) and developer (debug/system) modes. |
🚀 Installation
1. Require the Package
composer require laravel-cortex/cortex
2. Run the Installer
This interactive command helps you choose your stack and publishes necessary assets.
php artisan cortex:install
3. Add to Layout
Depending on your stack, add the standard component or script.
🟢 Livewire (TALL Stack)
Add this to your main layout (e.g., layouts/app.blade.php) before the closing </body> tag:
<livewire:cortex-palette />
� Blade (Vanilla JS)
For traditional Laravel apps without Livewire:
<script src="{{ asset('vendor/cortex/js/cortex.js') }}"></script>
🔵 API (Next.js / React / Vue)
Cortex exposes a REST API for headless apps.
GET /api/cortex/search?query=...POST /api/cortex/execute
🎮 Usage
Press Cmd+K (Mac) or Ctrl+K (Windows) to open the palette.
1. Navigation & Search
Just start typing. Cortex indexes all your named routes automatically via the cortex:index command.
- Type "Users" → Finds
UserController@index. - Type "Settings" → Finds
ProfileController@edit.
2. AI Commands (The Magic 🪄)
If enabled, Cortex sends sentence-length queries (> 3 words) to OpenAI/Gemini.
- "Delete students named John"
- "Create a new product called 'Super Widget'"
- "Switch to Acme Corp"
How it works:
- Intent Recognition: AI determines if you want to View, Create, or Delete.
- Safety Check: For destructive actions, Cortex calculates the impact (e.g., "5 records found") and asks for confirmation.
- Execution: Runs the action securely.
3. Multi-Tenant Switching
Cortex can search your Tenant model (e.g., Organization).
- Type the name of the tenant (e.g., "Google").
- Press Enter to switch context.
- The Session key
current_tenant_idis updated automatically.
⚙️ Configuration & Environment
Control Cortex behavior via your .env file.
| Variable | Default | Description |
|---|---|---|
CORTEX_AI_ENABLED |
true |
Enable/Disable Natural Language interaction. |
CORTEX_AI_DRIVER |
openai |
AI Provider (openai, gemini). |
OPENAI_API_KEY |
null |
Your LLM API Key. |
CORTEX_TENANTS_ENABLED |
false |
Enable the Organization switcher. |
CORTEX_TENANT_MODEL |
App\Models\Organization |
The model class for your tenants. |
CORTEX_MODE |
client |
Crucial Setting (See below). |
CORTEX_STACK |
livewire |
Controls which assets invoke the runner (livewire, blade, api). |
🛠️ Developer vs Client Mode (CORTEX_MODE)
client(Default):- Hides technical system routes.
- Shows user-friendly descriptions ("View Profile" instead of
profile.edit). - Hides "Dangerous" system commands (Clear Cache, etc).
developer:- Shows exact Route URIs (
/users/{id}/edit). - Enables System Actions like
optimize:clear,route:list. - Great for admins and developers debugging the app.
- Shows exact Route URIs (
🛡️ Security & Permissions
Cortex is secure by default. It respects your application's existing authorization gates.
- Middleware Check: Routes with
middleware('can:manage-users')are hidden from users without that permission. - Policy Check: It checks
Gate::allows()against route actions automatically. - Authentication: Guest users only see Public routes (e.g., Login, Register). Authenticated users see what their role allows.
Note for API Users:
When using the API (/api/cortex/search), ensure you send the request with an Authenticated Session (cookies) or Bearer Token. Unauthenticated requests will be treated as "Guest".
� Advanced Customization
Publish the configuration file to define custom actions and searchable models.
php artisan vendor:publish --tag=cortex-config
Defining Searchable Models
In config/cortex.php:
'models' => [ 'product' => [ 'class' => 'App\Models\Product', 'searchable' => ['name', 'sku'], 'actions' => [ 'view' => 'products.show', 'edit' => 'products.edit', ] ] ]
🤝 Contributing
We love contributions! Please submit Pull Requests to the GitHub repository.
📄 License
The MIT License (MIT). Please see License File for more information.
laravel-cortex/cortex 适用场景与选型建议
laravel-cortex/cortex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 laravel-cortex/cortex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laravel-cortex/cortex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-24

