Overview
The Blog feature in LaraCMS provides a complete content management system for creating, organizing, and publishing blog posts. Posts support rich text content, featured images, categorization, and tagging.Database Structure
- Posts Table
- Categories Table
The Reference:
posts table stores all blog content with the following structure:database/migrations/2025_03_31_154815_create_posts_table.php:14Model Relationships
Post Model
ThePost model defines relationships with users, categories, and tags:
app/Models/Post.php:7
User Workflows
Creating a Blog Post
Creating a Blog Post
Admin Workflow
-
Navigate to Blog Management
- Go to
/admin/blog/poststo view all posts - Click “Create New Post” or navigate to
/admin/blog/create
- Go to
-
Fill Post Details
- Title: Enter a descriptive title (min 8 characters, max 255)
- Slug: Auto-generated URL-friendly identifier (must be unique)
- Body: Rich text content for the post
- Featured Image: Upload an optional post image (stored in
storage/images/)
-
Organize Content
- Select one or more categories from the dropdown
- Add relevant tags for searchability
-
Publish or Save as Draft
- Status defaults to
draft - Set
is_publishedto true when ready to go live published_attimestamp records when post goes live
- Status defaults to
POST /admin/blog/postsController:
BlogController@storeReference:
app/Http/Controllers/BlogController.php:63Editing a Blog Post
Editing a Blog Post
Edit Workflow
-
Access Edit Screen
- From the posts list at
/admin/blog/posts - Click “Edit” on any post to go to
/admin/blog/posts/{post}/edit
- From the posts list at
-
Update Content
- Modify title, body, or featured image
- Change categories or tags as needed
- Update validation ensures title uniqueness (except for current post)
-
Save Changes
- Form submits to
PATCH /admin/blog/posts/{post}/update - System syncs categories and tags relationships
- Flash message confirms successful update
- Form submits to
PATCH /admin/blog/posts/{post}/updateController:
BlogController@updateReference:
app/Http/Controllers/BlogController.php:104Deleting a Blog Post
Deleting a Blog Post
Delete Workflow
-
Initiate Delete
- Click “Delete” button on post list or edit screen
-
Authorization Check
- System verifies user has
deletepermission via Gate
- System verifies user has
-
Cascade Deletion
- Post record is removed
- Related pivot table entries (categories, tags) are automatically deleted
- Featured image remains in storage (manual cleanup may be needed)
DELETE /admin/blog/posts/{post}Controller:
BlogController@destroyReference:
app/Http/Controllers/BlogController.php:133Frontend Display
Blog Index
Route:
Reference:
GET /blogDisplays paginated list of all published posts ordered by published_at (newest first).- Shows 8 posts per page
- Accessible to all visitors
- Links to individual post pages
PostController@indexReference:
routes/web.php:58Single Post
Route:
Reference:
GET /blog/{slug}Displays full post content including:- Title and featured image
- Author information (via
userrelationship) - Post body content
- Categories and tags
- Engagement metrics (views, likes, comments)
PostController@showReference:
routes/web.php:59Validation Rules
When creating or updating posts, the system enforces:app/Http/Controllers/BlogController.php:67
Permissions
Blog management requires specific permissions:- View Posts:
access.admin.panelmiddleware required - Create Posts:
creategate authorization onPostclass - Update Posts:
updategate authorization on specific post - Delete Posts:
deletegate authorization on specific post
File Storage
Featured images are stored using Laravel’s Storage system:storage/app/public/images/Public URL:
/storage/images/{filename}Reference:
app/Http/Controllers/BlogController.php:80
Key Routes
| Method | URI | Action | Description |
|---|---|---|---|
| GET | /admin/blog/posts | BlogController@index | List all posts |
| GET | /admin/blog/create | BlogController@create | Show create form |
| POST | /admin/blog/posts | BlogController@store | Store new post |
| GET | /admin/blog/posts/{post}/edit | BlogController@edit | Show edit form |
| PATCH | /admin/blog/posts/{post}/update | BlogController@update | Update post |
| DELETE | /admin/blog/posts/{post} | BlogController@destroy | Delete post |
| GET | /blog | PostController@index | Frontend post list |
| GET | /blog/{slug} | PostController@show | Frontend single post |
routes/web.php:93-99