将博客系统集成到您的 Doctype Admin 的软件包

v1.0.3 2020-10-10 14:14 UTC

This package is auto-updated.

Last update: 2024-08-29 05:16:01 UTC


README

Doctype Admin Blog

Issues Latest Stable Version Stars Total Downloads Issues

Laravel 7 Admin Panel for lazy developers.

包含: -

  • 帖子管理
  • 分类管理

安装

运行 Composer Require 命令

composer require doctype_admin/blog

安装软件包资源

安装所有资源

php artisan DoctypeAdminBlog:install -a

此命令将发布

  • 名为 Blog.php 的配置文件
  • 帖子视图和分类视图文件
  • 迁移文件
  • 种子文件

仅安装配置文件

php artisan DoctypeAdminBlog:install -c

仅安装视图文件

php artisan DoctypeAdminBlog:install -f

仅安装迁移文件

php artisan DoctypeAdminBlog:install -m

仅安装种子文件

php artisan DoctypeAdminBlog:install -d

然后迁移数据库

php artisan migrate

此软件包包括两个种子

  • PostsTableSeeder
  • CategoriesTableSeeder

要使用特定种子,请使用

php artisan db:seed --class=CategoriesTableSeeder //Seed this first
php artisan db:seed --class=PostsTableSeeder // And then this

注意

如果找不到种子类,请尝试运行 composer dump-autoload

更新说明

  • 博客路由已从前缀 admin/post 和 admin/category 更改为 admin/blog/post 和 admin/blog/category

软件包配置文件

<?php

return [


    /*
    |--------------------------------------------------------------------------
    | Doctype Admin Post Tagging Feature
    |--------------------------------------------------------------------------
    |
    | This option define whether to use post tagging feature provided by the
    | package.This package uses https://github.com/rtconner/laravel-tagging
    |
    */
    'post_tagging' => true,

    /*
    |--------------------------------------------------------------------------
    | Doctype Admin Blog default prefix
    |--------------------------------------------------------------------------
    |
    | This option defines the default prefix of all routes of blog plugins to
    | your admin panel. The default prefix is admin. You can change the prefix
    | but we highly recommend to use default one.
    */
    'prefix' => 'admin',

    /*
    |--------------------------------------------------------------------------
    | Doctype Admin Blog Middlewares
    |--------------------------------------------------------------------------
    |
    | This option includes all the middleware used by routes og doctype admin
    | blog package.
    | Note: If you don;t want activity logging of post and category model simply
    | remove activity middleware
    |
    */
    'middleware' => ['web', 'auth', 'activity'],

    /*
    |--------------------------------------------------------------------------
    | Doctype Admin Blog Thmbnail Feature
    |--------------------------------------------------------------------------
    |
    | This option defines whether to use Package's Thumbnail Featured or not
    | Default option is true
    |
    */
    'thumbnail' => true,

    /*
    |--------------------------------------------------------------------------
    | Thumbnail Qualities
    |--------------------------------------------------------------------------
    |
    | These options are default post image and its thumbnail quality
    |
    |
    */

    'image_quality' => 80,
    'medium_thumbnail_quality' => 60,
    'small_thumbnail_quality' => 30,

    /*
    |--------------------------------------------------------------------------
    | Default Image Fit Size
    |--------------------------------------------------------------------------
    |
    | These option is default post imahe height and width fit size
    |
    |
    */

    'img_width' => 1000,
    'img_height' => 800,

    'medium_thumbnail_width' => 800,
    'medium_thumbnail_height' => 600,

    'small_thumbnail_width' => 400,
    'small_thumbnail_height' => 300,

];

要将软件包路由链接添加到侧边菜单以便访问,请在 config/adminlte.php 中添加以下内容在 'menu' 键下

        [
            'text' => 'Blog',
            'icon' => 'fas fa-blog',
            'submenu' => [
                           [
                               'text' => 'Posts',
                               'icon' => 'fas fa-file',
                               'url' => 'admin/blog/post',
                           ],
                           [
                             'text' => 'Categories',
                             'icon' => 'fas fa-bezier-curve',
                             'url' => 'admin/blog/category',
                           ]
                          ]
        ],

帖子作用域

缓存帖子

Doctype admin blog 使用外观 "Post" 来检索缓存数据。

相关帖子用法

$post = Post::find($id);
scopeRelatedTagPost = Post::relatedPost($post); //retrives all the related posts to $post using some or all tags used by $post

$scopeRelatedTagPostlimited = Post::relatedPost($post,8); //retrives 8 related post, default limit is 5

类似的还有 relatedTagPost 和 relatedPost。

注意

  • relatedTagPost 作用域使用实例中使用的标签来查找其他相关帖子
  • 如果您想使用 doctype admin panel 提供的 ModelScope,只需在 Post 模型上使用 ModelScopes 即可

与软件包一起工作

我们的帖子模型

<?php

namespace doctype_admin\Blog\Models;

use App\User;
use Conner\Tagging\Taggable;
use doctype_admin\Blog\Models\Category;
use doctype_admin\Blog\Traits\PostScopes;
use Illuminate\Database\Eloquent\Model;
use App\Traits\ModelScopes;
use Cviebrock\EloquentSluggable\Sluggable;

class Post extends Model
{
    use Taggable, PostScopes, ModelScopes, Sluggable;

    protected $guarded = [];

    public function save(array $options = [])
    {
        // If no author has been assigned, assign the current user's id as the author of the post
        if (!$this->author_id && Auth::user()) {
            $this->author_id = Auth::user()->getKey();
        }

        return parent::save();
    }

    public function author()
    {
        return $this->belongsTo(User::class, 'author_id');
    }

    public function category()
    {
        return $this->belongsTo(Category::class, 'category_id');
    }

    public function getStatusAttribute($attribute)
    {
        return [
            1 => "Pending",
            2 => "Draft",
            3 => "Published"
        ][$attribute];
    }

    /**
     * Return the sluggable configuration array for this model.
     *
     * @return array
     */
    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }
}

有什么新功能?

新增缩略图特色

如何使用缩略图?只需按照以下方式使用

   @foreach ($images as $image)
       <img src="{{asset($image->thumbnail('small'))}}"> // For small thumbnail
   <img src="{{asset($image->thumbnail('medium'))}}"> // For medium thumbnail
   @endforeach

管理面板截图

Doctype Admin Blog Doctype Admin Blog Doctype Admin Blog

待办事项

  • 更好的配置文件控制
  • 帖子分析
  • Algolia 帖子搜索功能
  • 可维护性
  • 更好的 UI

使用的软件包

许可证

MIT

DOCTYPE NEPAL ||DR.H2SO4