orchid / cms
Requires
- cviebrock/eloquent-sluggable: ^7.0
- orchid/platform: ^7.0|dev-master
README
此包正在寻找维护者! 如果你想成为其中一员,请发送邮件至 bliz48rus@gmail.com
内容管理系统实体
实体是Press内容管理系统的主要部分。您不必为每个模型生成CRUD,只需选择单独类型中的任何对象即可轻松管理。本质仅适用于基于'Post'的模型,因为它是典型数据的基。
请描述您希望接收的字段及其形式,然后CRUD将自动构建。
您可以使用以下命令创建实体
// Create entity for one record php artisan orchid:entity-single // Create entity for many records php artisan orchid:entity-many
要将实体显示给用户,您必须使用图形界面赋予它或组(角色)必要的权限。
类型看起来像这样
namespace DummyNamespace; use Orchid\Press\Entities\Many; class DummyClass extends Many { /** * @var string */ public $name = ''; /** * @var string */ public $slug = ''; /** * @var string */ public $icon = ''; /** * Slug url /news/{name}. * @var string */ public $slugFields = ''; /** * Rules Validation. * @return array */ public function rules() { return []; } /** * @return array */ public function fields() { return []; } /** * Grid View for post type. */ public function grid() { return []; } /** * @return array */ public function options() { return []; } }
您可以使用所有可用方法扩展数据类型,为其添加适合您应用程序的新功能。
网格修改
您可以通过传递一个包含名称和函数的数组(而不是键值对)来更改要在网格中显示的数据,其中传递的参数是原始数据切片。
/** * Grid View for post type. */ public function grid() { return [ TD::set('name','Name'), TD::set('publish_at','Date of publication'), TD::set('created_at','Date of creation'), TD::name('full_name','Full name')->render(function($post){ return "{$post->getContent('fist_name')} {$post->getContent('last_name')}"; }) ]; }
帖子
press假定默认情况下,包含网站数据的任何元素都是Post
模型。这种结构适合大多数公共网站,因为它们的结构非常相似。例如
- 新闻
- 促销
- 页面
- 职位空缺
您可以想出数百种变化。为了避免使用几乎相同的模型和迁移,使用基本的Post
模型。它使用JSON类型列,比EAV格式更方便、更简单。它还允许进行翻译。我们专门为Laravel和WordPress重现了一些方法,这将使您更有效率。
获取数据
现在您可以获取数据库数据
use Orchid\Press\Models\Post; $posts = Post::all();
// All posted posts $posts = Post::published()->get(); $posts = Post::status('publish')->get(); // Specific entry $post = Post::find(42); // Post name based on the current localization echo $post->getContent('name');
能够将本地化存储在JSON中并不意味着您必须填写所有值。例如,有关酒吧的信息记录,它可以有俄语和英语,但座位数不会因任何语言而改变。相应地,复制此类参数没有意义,但应将它们放在options
中。
// Specific entry $post = Post::find(42); // All options echo $post->getOptions(); // Get all localization parameters from options echo $post->getOption('locale'); // If the option does not exist or is not specified // you can specify the second parameter that will be returned. echo $post->getOption('countPlace',10);
单表继承
如果您选择为自定义帖子类型创建新类,您可以返回该类以处理该帖子类型的所有实例。
写行为定义基于指定的type
。
//All objects in the $videos collection will be Post instances $videos = Post::type('video')->status('publish')->get();
分类学
您可以为特定帖子获取分类学,例如
$post = Post::find(42); $taxonomy = $post->taxonomies()->first(); echo $taxonomy->taxonomy;
或者,您可以使用您的分类法来搜索记录
$post = Post::taxonomy('category', 'php')->first();
可能存在更复杂的形式,例如,获取主分类及其子分类的所有条目
$posts = Post::whereHas('taxonomies.term', function($query){ $query->whereIn('slug', Category::slug('main')->with('childrenTerm') ->first()->childrenTerm->pluck('term.slug') ); })->get()
请注意,这类记录的采样率可能较低,这里仅作为示例。
分类和分类学
您可以使用以下方法从特定分类检索分类、分类学或记录
// All categories $category = Taxonomy::category()->slug('uncategorized')->posts()->first(); // Only all categories and entries associated with it $category = Taxonomy::where('taxonomy', 'category')->with('posts')->get(); $category->each(function($category) { echo $category->term->getContent('name'); }); // all posts from category $category = Category::slug('uncategorized')->posts()->first(); $category->posts->each(function($post) { echo $post->getContent('name'); });
附件
附件是与录音相关的文件。这些文件可以有不同的格式和分辨率。
$item = Post::find(42); $image->attachment()->first(); $image->url();
全文搜索
要使用全文搜索,您需要在行为类中添加一个新方法
/** * Get the indexable data array for the model. * * @param $array * * @return mixed */ public function toSearchableArray($array) { // Customize array... return $array; }
它将接受所有模型数据,并返回索引所需的元素。
以标准的“DemoPost.php”为例,它有许多参数,但实际上我们只需要两个
- 文章标题
- 文章内容
为此,我们必须返回它们
/** * Get the indexable data array for the model. * * @param $array * * @return mixed */ public function toSearchableArray($array) { $array['content']['en']['id'] = $array['id']; return $array['content']['en']; }
我们以英语返回所有数据,并附上邮编。
导入时,只需应用该命令即可
php artisan scout:import Orchid\\Press\\Models\\Post
现在我们可以在我们的项目中使用搜索
use Orchid\Press\Models\Post; $articles = Post::search('как пропатчить kde2 под freebsd')->get();
标签
标签(标签)- 可以将一组关于某个主题的文本、图像等联系起来的单词或短语
可以使用特质将标签连接到所有创建的模型
use Orchid\Press\TraitsTaggableTrait; class Product extends Eloquent { use TaggableTrait; }
在Post
模型中,它默认包含,因此示例将在其上。在本节中,我们将向您展示如何管理您的标签主题。
use Orchid\Press\Models\Post; // Get the entity object $post = Post::find(1); // Through a string $post->tag('foo, bar, baz'); // Through an array $post->tag([ 'foo', 'bar', 'baz']);
通过数组或实体分隔的字符串从对象中删除一个或多个标签。
// Get the entity object $post = post::find(1); // Through a string $post->untag('bar, baz'); // Through an array $post->untag(['bar', 'baz']); // Remove all the tags $post->untag();
此方法与tag()
方法非常相似,但它结合了untag()
以自动识别要添加和删除的标签。当运行主题更新且不想处理检查以确定哪些标签应添加或删除时,这是一种有益的技术。
// Get the entity object $post = Post::find(1); // Through a string $post->setTags('foo, bar, baz'); // Through an array $post->setTags(['foo', 'bar', 'baz']); // Using the `slug` column $post->setTags(['foo', 'bar', 'baz'], 'slug');
我们有几种方法可以帮助您获取附加到对象的全部标签,以及相反地获取具有给定标签的所有对象。
// Get the entity object $post = Post::whereTag('foo, bar')->get(); $post = Post::find(1); $tags = $post->tags; $tags = Post::allTags();
评论
对于某些类型的网站来说,评论是必需的属性。多亏了它们,用户可以对任何记录发表意见,支持或反驳所表达的意见,与其他用户进行对话。
评论附加到Post条目
use Orchid\Press\Models\Comment; use Orchid\Press\Models\Post; $post = Post::find(42); $comment = Comment::create([ 'post_id' => $post->id, 'user_id' => Auth::id(), 'parent_id' => 0, 'content' => 'Any text', 'approved' => 1, ]);
关系
// Retrieve all comments for a specific Post $comments = Comment::findByPostId(42); $comment = Comment::find(1); // Get in touch with Post $post = $comment->post(); // Get parent comment $comment = $comment->original(); // Get child comments $comment = $comment->replies(); // Get the author of the comment $comment = $comment->author();
检查
$comment = Comment::find(1); // Check if a comment has been posted $comment->isApproved(); // Check if a comment is a response to another comment $comment->isReply(); // Check if the comment has answers $comment->hasReplies();
菜单
该包包括一个易于使用的机制,用于使用拖放和本地化支持创建自定义菜单(导航)。
配置
大多数菜单都显示在网站的顶部,但不同应用程序的位置可能不同,菜单的数量受限于在配置文件config/press.php
中定义的数目。
'menu' => [ 'header' => 'Top Menu', 'sidebar' => 'Sidebar Menu', 'footer' => 'Footer Menu', ],
模型
菜单类是一个常规的Eloquent
模型,它具有所有这些功能,例如,要仅显示带有子链接的父菜单项并考虑本地化,则需要
namespace Orchid\Press\Models\Menu; $menu = Menu::where('lang', app()->getLocale()()) ->where('parent',0) ->where('type', 'footer') ->with('children') ->get();
可用方法
//First child $menu = Menu::find(1)->children()->first(); //Parent element $menu = Menu::find(1)->parent()->get();
许可协议
MIT 许可协议(MIT)。请参阅许可文件获取更多信息。