imagina / iblog-module

安装次数: 2,781

依赖项: 2

建议者: 0

安全性: 0

星标: 1

关注者: 5

分支: 10

开放问题: 2

语言:Blade

类型:asgard-module

10.0.0 2024-06-11 21:00 UTC

README

博客模块允许授权用户维护博客。博客是一系列带有时戳的帖子,通常按日期查看,就像查看日志一样。博客条目可以是公开的或私有的,具体取决于哪些角色可以访问内容。

安装

  • composer require imagina/iblog-module
  • php artisan module:migrate Iblog

端点

路由基础: https://yourhost.com/api/iblog/v1/

  • 帖子

    • 属性

      • 标题: 字符串 (可翻译)
      • 描述: 字符串 (可翻译)
      • 别名: 字符串 (可翻译)
      • 摘要: 字符串 (可翻译)
      • meta标题: 字符串 (可翻译)
      • meta描述: 字符串 (可翻译)
      • meta关键词: 字符串 (可翻译)
      • 可翻译选项: 字符串 (可翻译)
      • 选项: 字符串
      • 分类ID: 字符串
      • 分类: 数组
      • 标签: 数组
      • 用户ID: 字符串
      • 状态: 字符串
      • 创建时间: 字符串
    • 创建

      • 方法: POST
      • URI: /posts
    • 读取

      • 方法: GET
      • URI: /posts/:id
      • URI: /posts
    • 更新

      • 方法: PUT
      • URI: /post/:id
    • 删除

      • 方法: DELETE
      • URI: /posts/:id
  • 分类

    • 属性

      • 父ID: 整数
      • 选项: 文本
      • 标题: 字符串 (可翻译)
      • 别名: 字符串 (可翻译)
      • 描述: 文本 (可翻译)
      • meta标题: 文本 (可翻译)
      • meta描述: 文本 (可翻译)
      • 可翻译选项: 文本 (可翻译)
    • 创建

      • 方法: POST
      • URI: /categories
    • 读取

      • 方法: GET
      • URI: /categories/:id
      • URI: /categories
    • 更新

      • 方法: PUT
      • URI: /categories/:id
    • 删除

      • 方法: DELETE
      • URI: /categories/:id

设置关系

由于我们无法直接编辑我们的 Iblog 模块,因为它由 composer 管理,因此我们需要编辑我们的应用程序中 /config/asgard/iblog/ 文件夹中的 config.php 文件,以与其他模块建立关系。

导航到名为“动态关系”的部分,默认情况下看起来像这样

'relations' => [
        'category'=>[
         'store' => function () {
                return $this->belongsTo(
                    \Modules\Marketplace\Entities\Store::class);
            },
        ],
        'post'=>[
            'store' => function () {
                return $this->belongsTo(
                    \Modules\Marketplace\Entities\Store::class);
            },
        ],
]

现在我们可以使用 $post->store->name$category->store->name 分别访问 iblog 帖子或分类的信息。

在帖子或分类表中添加数据如果您真的需要在分类或帖子表中添加额外的列,例如,如果您想添加一个关系列或额外的查询字段。我们需要编辑我们的应用程序中 /config/asgard/iblog/ 文件夹中的 config.php 文件。其中有一个包含对象可填充字段的数组的 fillable 键。

  /*
    |--------------------------------------------------------------------------
    | Fillable user fields
    |--------------------------------------------------------------------------
    | Set the fillable post and category fields, those fields will be mass assigned
    */
    'fillable' => [
       'post'=>[
           'options',
           'category_id',
           'user_id',
           'status',
           'created_at'
       ],
        'category'=>[
            'parent_id',
            'options'
        ]
    ],

将您想要的字段添加到这个数组中。

  /*
    |--------------------------------------------------------------------------
    | Fillable user fields
    |--------------------------------------------------------------------------
    | Set the fillable post and category fields, those fields will be mass assigned
    */
    'fillable' => [
       'post'=>[
           'options',
           'category_id',
           'user_id',
           'status',
           'created_at',
           'store_id'
       ],
        'category'=>[
            'parent_id',
            'options',
            'store_id'
        ]
    ],