Skip to main content
The blog management system allows administrators to create, edit, and organize blog content with categories and tags.

Permission Requirements

All blog management features require the access.admin.panel permission. Additionally, post creation and editing use Laravel’s Gate authorization.

Blog Post List

View and manage all blog posts at /admin/blog/posts.

Features

  • Paginated post listing (10 posts per page)
  • Quick edit and delete actions
  • Post status indicators
  • Author information
// app/Http/Controllers/BlogController.php:26-33
public function index()
{
    $posts = Post::query()
        ->paginate(10)
        ->withQueryString();

    return view('admin.blog.posts', ['posts' => $posts]);
}

Creating a Blog Post

Create new blog posts with rich content, categories, and tags.
1

Navigate to Create Post

Go to /admin/blog/create or click “Create New Post” button
2

Fill Post Details

Enter title, body content, and slug. The system validates:
  • Title: Required, unique, 8-255 characters
  • Slug: Required, unique (for URL-friendly permalinks)
  • Body: Required (rich text content)
3

Add Featured Image

Upload an optional post image (stored in storage/public/images)
4

Select Category

Choose from existing blog categories (optional)
5

Add Tags

Select multiple tags for better content organization (optional)
6

Publish Post

Click save to publish the post immediately

Validation Rules

// app/Http/Controllers/BlogController.php:67-75
$validated = $request->validate([
    'title' => 'required|unique:posts|min:8|max:255',
    'post_image' => 'file',
    'body' => 'required',
    'slug' => 'required|unique:posts,slug',
    'category_id' => 'nullable|exists:blog_categories,id',
    'tags' => 'nullable|array',
    'tags.*' => 'exists:tags,id'
]);

Authorization Gate

Post creation is protected by Laravel’s Gate authorization:
// app/Http/Controllers/BlogController.php:40
Gate::authorize('create', $post);

Editing Blog Posts

Edit existing blog posts at /admin/blog/posts/{post}/edit.
1

Access Post Editor

Click “Edit” on any post in the blog list
2

Modify Content

Update title, body, image, category, or tags
3

Save Changes

System validates uniqueness (except for current post)

Edit Validation

// app/Http/Controllers/BlogController.php:108-115
$validated = $request->validate([
    'title' => 'required|min:8|max:255|unique:posts,title,' . $post->id,
    'post_image' => 'file',
    'body' => 'required',
    'category_id' => 'nullable|exists:blog_categories,id',
    'tags' => 'nullable|array',
    'tags.*' => 'exists:tags,id'
]);

Livewire Blog Edit Component

The BlogEdit Livewire component provides reactive editing:
// app/Livewire/Admin/BlogEdit.php:9-25
class BlogEdit extends Component
{
    public Post $post;

    public function mount($id)
    {
        $this->post = Post::findOrFail($id);
    }

    public function render()
    {
        return view('livewire.admin.blog-edit', [
            'posts' => Auth::user()->posts,
        ]);
    }
}

Deleting Blog Posts

Delete posts with authorization checks.
Post deletion is permanent and cannot be undone. The post will be removed from the database along with its relationships.
// app/Http/Controllers/BlogController.php:133-142
public function destroy(Post $post)
{
    Gate::authorize('delete', $post);

    $post->delete();

    session()->flash('message', 'Post Deleted Successfully.');

    return back();
}

Blog Categories

Organize posts into categories at /admin/blog/categories.

Category Features

  • Create and manage blog categories
  • Assign multiple posts to a category
  • Categories are optional but recommended

Post-Category Relationship

// app/Models/Post.php:16-19
public function blogCategories()
{
    return $this->belongsToMany(BlogCategory::class, 'blog_category_post');
}

Tags System

Use tags for flexible content organization.

Tag Features

  • Multiple tags per post
  • Tag-based filtering
  • Managed through the post editor

Post-Tag Relationship

// app/Models/Post.php:21-24
public function tags()
{
    return $this->belongsToMany(Tag::class);
}

Syncing Tags

Tags are synchronized during post creation and updates:
// app/Http/Controllers/BlogController.php:84
$post->tags()->sync($validated['tags'] ?? []);

Post Model Structure

The Post model defines core attributes and relationships:
// app/Models/Post.php:8-25
class Post extends Model
{
    protected $fillable = ['user_id', 'title', 'body', 'slug', 'post_image'];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function blogCategories()
    {
        return $this->belongsToMany(BlogCategory::class, 'blog_category_post');
    }

    public function tags()
    {
        return $this->belongsToMany(Tag::class);
    }
}

Image Management

Uploading Post Images

Images are stored using Laravel’s storage system:
// app/Http/Controllers/BlogController.php:79-81
if ($request->hasFile('post_image')) {
    $validated['post_image'] = Storage::disk('public')->put('images', $request->file('post_image'));
}

Image Storage Location

  • Storage path: storage/app/public/images/
  • Public URL: storage/images/{filename}
  • Disk: public (configured in config/filesystems.php)

Admin Blog Routes

All blog admin routes are prefixed with /admin and protected:
// routes/web.php:93-100
Route::get('/blog/posts', [BlogController::class, 'index'])->name('blog.posts');
Route::get('/blog/create', [BlogController::class, 'create'])->name('blog.create');
Route::post('/blog/posts', [BlogController::class, 'store'])->name('blog.store');
Route::get('/blog/posts/{post}', [BlogController::class, 'show'])->name('blog.show');
Route::get('/blog/posts/{post}/edit', [BlogController::class, 'edit'])->name('blog.edit');
Route::delete('/blog/posts/{post}', [BlogController::class, 'destroy'])->name('blog.destroy');
Route::patch('/blog/posts/{post}/update', [BlogController::class, 'update'])->name('blog.update');
Route::get('/blog/categories', [BlogController::class, 'categories'])->name('blog.categories');

Best Practices

Always create unique, descriptive slugs for better SEO:
  • Use lowercase letters
  • Replace spaces with hyphens
  • Avoid special characters
  • Keep it concise (3-5 words)
Use categories and tags effectively:
  • Categories: Broad topics (5-10 categories)
  • Tags: Specific keywords (unlimited)
  • Don’t duplicate categories as tags
Respect post ownership:
  • Only authors can edit their own posts
  • Admins can edit all posts
  • Use Gates for authorization checks

Troubleshooting

Common validation issues:
  • Duplicate slug: Change the slug to be unique
  • Title too short: Must be at least 8 characters
  • Missing body: Content is required
  • Invalid category: Select from existing categories
Check the following:
  • File size within server limits
  • Storage directory is writable
  • Symbolic link exists: php artisan storage:link
  • Correct disk configuration in config/filesystems.php
If you see “This action is unauthorized”:
  • Verify access.admin.panel permission
  • Check post ownership (if editing)
  • Review Policy definitions
  • Ensure proper role assignment

Next Steps

Gallery Management

Learn how to manage photos and albums

User Management

Manage users who can create blog posts

Build docs developers (and LLMs) love