Skip to content

pratiksh404/doctype_admin_blog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Doctype Admin Blog

Issues Latest Stable Version Stars Total Downloads Issues

Laravel 7 Admin Panel for lazy developers.

Contains : -

  • Post Management
  • Category Management

Installation

Run Composer Require Command

composer require doctype_admin/blog

Install package assets

Install all assets

php artisan DoctypeAdminBlog:install -a

This command will publish

  • config file named Blog.php
  • views files of post and category
  • migrations files
  • seed files

Install config file only

php artisan DoctypeAdminBlog:install -c

Install view files only

php artisan DoctypeAdminBlog:install -f

Install migrations files only

php artisan DoctypeAdminBlog:install -m

Install seed files only

php artisan DoctypeAdminBlog:install -d

Then migrate database

php artisan migrate

This Package includes two seed

  • PostsTableSeeder
  • CategoriesTableSeeder

To use specific seed use

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

Note

If seed class is not found try running composer dump-autoload

Update Note

  • Blog Routes has been changed from prefix admin/post and admin/category to admin/blog/post and admin/blog/category

Package Config File

<?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,

];

To add the package route link to be accesable from sidemenu just add following on config/adminlte.php undr key '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',
                           ]
                          ]
        ],

Post Scopes

Scopes Description
Post::featured()->get() Retives all featured posts
Post::featuredLimit($limit)->get() Retives $limit(type integer) no. of posts
Post::published()->get() Retrives published posts
Post::draft()->get() Retrives draft posts
Post::pending()->get() Retrives pending
posts

Cached Posts

Doctype admin blog uses facade "Post" to retrive cached data.

Use Description
Post::allPosts Retives all posts
Post::pendingPosts Retives Pending Posts
Post::draftPosts Retrives draft posts
Post::publishedPosts Retrives published posts
Post::blog Retrives Blog posts
Post::event Retrives event posts
Post::news Retrives news posts
Post::job Retrives job posts
Post::relatedTagPosts(post,limit) Retrives limit no. of posts related to post arguement instance tag
Post::relatedCategoryPosts($post,$limit) Retrives limit no. of posts related to post arguement instance category
Post::relatedPosts($post,$limit) Retrives limit no. of posts related to post arguement instance tag and category

Related Post Usages

$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

similar goes to relatedTagPost and relatedPost.

Note

  • relatedTagPost scopes uses tags used by the instance to find out other related post using its tags.
  • If you want to use ModelScope provied by doctype admin panel just use ModelScopes on Post Model

Working with package

Our Post Model

<?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'
            ]
        ];
    }
}

What's New ?

New Thumbnail featured added

How to use thumbnails ? Just use as follows

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

Admin Panel Screenshot

Doctype Admin Blog Doctype Admin Blog Doctype Admin Blog

Todos

  • Better Confile File Control
  • Post Analytics
  • Algolia Post Search Funtionality
  • Maintainabilty
  • Better UI

Package Used

License

MIT

DOCTYPE NEPAL ||DR.H2SO4