laradium / laradium-content
v2.0.4
2020-04-16 15:05 UTC
- dev-master
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.1
- v1.0.0
- dev-l5.8
- dev-interface-builder
- dev-temp-master
- dev-l5.7
- dev-fix/sidebar-gap
- dev-feature/page-api
- dev-feature/previewable_pages
- dev-feature/sitemap-middleware
- dev-feature/custom_sitemap_url
- dev-LAR-10
- dev-LAR-7
- dev-LAR-16
- dev-LAR-3
- dev-LAR-4
This package is not auto-updated.
Last update: 2024-09-27 11:46:25 UTC
README
安装
本地使用
- 在
composer.json
文件中将此添加到您的项目仓库列表
"repositories": [
{
"type": "path",
"url": "../packages/laradium"
},
{
"type": "path",
"url": "../packages/laradium-content"
}
]
目录结构应如下所示
-Project
-packages
--laradium
--laradium-content
全局使用
"repositories": [
{
"type": "git",
"url": "https://github.com/laradium/laradium.git"
},
{
"type": "git",
"url": "https://github.com/laradium/laradium-content.git"
}
]
composer require laradium/laradium-content dev-master
php artisan vendor:publish --tag=laradium-content
- 使用您的偏好配置
config/laradium.php
文件 - 将 widgetConstructor 字段添加到您的
laradium.php
字段列表
'widgetConstructor' => \Laradium\Laradium\Content\Base\Fields\WidgetConstructor::class,
用法
默认情况下,提供了一个带有小部件构造器的主频道,允许您根据需要创建可排序的小部件块。
创建新频道
- 运行此命令(它将自动为您创建模型。您可以通过传递
--t
参数来创建翻译模型)
php artisan laradium:channel Blog
它将在 App\Laradium\Channels
下创建新的频道
它应如下所示
<?php
namespace App\Laradium\Channels;
use App\Models\Channels\Blog;
use Laradium\Laradium\Base\FieldSet;
use Laradium\Laradium\Content\Models\Page;
Class BlogChannel
{
/**
* @param FieldSet $set
*/
public function fields(FieldSet $set)
{
$set->morphsTo(Blog::class, Page::class)->fields(function (FieldSet $set) {
$set->text('author');
$set->wysiwyg('content');
})->morphName('content');
$set->widgetConstructor();
}
}
您需要为博客频道创建模型,您可以在其中指定所有需要的列,并通过使用 morphsTo
字段类型将它们添加到频道中
创建小部件
- 运行此命令
php artisan laradium:widget
(它将自动为您创建模型。您可以通过传递--t
参数来创建翻译模型)
它将在 App\Laradium\Widgets
下创建一个小部件
<?php
namespace App\Laradium\Widgets;
use App\Models\Widgets\Hiw;
use Laradium\Laradium\Base\FieldSet;
use Laradium\Laradium\Content\Base\AbstractWidget;
class HiwWidget extends AbstractWidget
{
/**
* @var string
*/
protected $model = Hiw::class;
/**
* @var string
*/
protected $view = 'widgets.HiwWidget';
/**
* @param FieldSet $set
* @return mixed|void
*/
public function fields(FieldSet $set)
{
$set->text('title')->translatable();
$set->text('description')->translatable();
$set->hasMany('items')->fields(function (FieldSet $set) {
$set->text('title')->translatable();
$set->text('description')->translatable();
})->sortable('sequence_no');
}
}
您可以在 fields
方法下指定您的字段。
页面解析器
要实际返回创建的页面,您需要在您的路由文件末尾或 RouteServiceProvider.php
文件中添加页面解析器路由。
为此,您可以使用辅助方法 content()->pageRoute()
,或者您可以创建自己的路由,但由于解析器路由是可配置的,因此通常不需要这样做。
配置文件提供了一些选项,以便在需要自定义时更改页面解析器的行为。
middlewares
- 更改解析器路由将使用哪些中间件custom_uri
- 提供了一个选项,用于定义一个返回自定义 uri 的函数名prepend_locale
- 向 uri 添加一个 iso 代码。因此,urlhttps://example.com/my-cool-page
将变为https://example.com/en/my-cool-page
uses
- 定义将用于实际解析路由的控制器和方法。