Build a Blog with Laravel
Build a Professional Laravel Blog: Complete CMS Tutorial
Master Laravel by building a complete blogging platform from scratch. This hands-on tutorial teaches you Laravel's core features including CRUD operations, authentication, file uploads, and rich text editing. Perfect for PHP developers looking to learn Laravel or expand their web development skills.
What You'll Build
- Full-featured blog with posts, categories, and comments
- User registration and authentication system
- Admin dashboard for content management
- Rich text editor (TinyMCE or CKEditor)
- Featured images and media uploads
- Responsive design with Blade templates
Laravel Concepts You'll Learn
- MVC Architecture: Organize code with Models, Views, and Controllers
- Eloquent Relationships: hasMany, belongsTo, and many-to-many relationships
- Laravel Migrations: Database schema management and version control
- Blade Components: Reusable UI components and layouts
- Form Validation: Server-side validation with Laravel's validator
- Authentication: Secure user registration and login with Laravel Sanctum
- File Storage: Handle image uploads with Laravel Storage
Prerequisites
- Basic PHP programming knowledge
- Understanding of HTML, CSS, and JavaScript fundamentals
- Composer package manager installed
- MySQL or PostgreSQL database setup
- Local development environment (Laravel Valet, XAMPP, or Docker)
Estimated Time: 6-8 hours. Work through each section at your own pace. Every step includes AI-ready prompts you can copy directly into Claude or ChatGPT for coding assistance.
Why Learn Laravel for Blog Development?
Laravel is the #1 PHP framework for modern web development, powering millions of applications worldwide. Building a blog with Laravel teaches you production-ready patterns used by professional development teams. Laravel's elegant syntax and comprehensive documentation make it the fastest way to build secure, scalable web applications.
This tutorial follows Laravel best practices and teaches proper MVC architecture. You'll learn to write clean, maintainable code that's easy to test and deploy. Check out our Laravel framework deep dive for more on why Laravel dominates PHP development.
Build a Blog with Laravel
Build a professional blog with Laravel, the elegant PHP framework that makes web development a joy. Laravel brings together powerful features like Eloquent ORM, Blade templating, and robust authentication out of the box, letting you focus on crafting compelling content rather than reinventing the wheel. With its expressive syntax, built-in testing tools, and extensive ecosystem, Laravel provides the perfect foundation for a blog that can grow from a personal journal to a content empire. Ideal for developers who appreciate clean code and convention over configuration.
Laravel Blog Setup: Installation and Project Configuration
Initialize Laravel project with composer
Initialize a new Laravel blog project using composer create-project laravel/laravel blog Set up the proper folder structure and organize routes (web.php for blog routes, api.php if needed) Configure the .env file with app name, environment settings, and debug mode Initialize git repository and create .gitignore for Laravel projects Set up proper directory permissions for storage and bootstrap/cache directories.
Configure PHPStorm/VS Code with Laravel extensions
Set up IDE workspace for Laravel development For VS Code, install extensions: Laravel Extension Pack, PHP Intelephense, Laravel Blade Snippets, and Laravel Extra Intellisense Create .vscode/settings.json with PHP formatting rules, blade formatter settings, and file associations Configure PHP CS Fixer or Laravel Pint for code style Add editor config for consistent formatting (PSR-12 standard, 4-space indent) Set up Xdebug configuration for debugging.
Laravel UI, Laravel Sanctum
Install essential Laravel packages for blog functionality Use composer to install laravel/ui for authentication scaffolding, laravel/sanctum for API authentication if needed Install additional packages: laravel/breeze or jetstream for modern auth, spatie/laravel-sluggable for automatic slug generation, intervention/image for image manipulation Run npm install to set up frontend dependencies Configure each package in config files and register service providers if needed.
Database and Environment Configuration for Laravel
Configure MySQL/PostgreSQL connection
Configure database connection in .env file. Choose between MySQL or PostgreSQL and set DB_CONNECTION, DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD Create the database using command line or GUI tool (MySQL Workbench, phpMyAdmin, or TablePlus) Test connection using php artisan migrate:status Configure database timezone and charset in config/database.php Set up separate testing database configuration for running tests.
Create posts, users, categories tables
Create database migrations for blog tables using php artisan make:migration Design posts table with columns: id, user_id, title, slug, content, excerpt, featured_image, published_at, timestamps Create categories table with id, name, slug, description Build posts_categories pivot table for many-to-many relationships Add proper foreign key constraints, indexes on slug and published_at columns Include soft deletes for posts Run migrations with php artisan migrate and verify table structure.
Set up Blade templates and Tailwind CSS
Set up Blade template structure in resources/views Create layouts/app.blade.php as the main layout with header, navigation, main content area, and footer Install and configure Tailwind CSS using npm install -D tailwindcss postcss autoprefixer, then npx tailwindcss init Configure tailwind.config.js to scan blade files Set up resources/css/app.css with Tailwind directives Create reusable Blade components for navigation, post cards, pagination, and footer Ensure responsive design with mobile-first approach. Compile assets with npm run dev or build.
Building Blog Features: Core Functionality and Admin Panel
Create Post, Category, User models
Create Eloquent models using php artisan make:model Build Post model with fillable fields (title, slug, content, excerpt, featured_image, published_at), relationships to User (belongsTo) and Category (belongsToMany), slug generation using spatie/sluggable, published scope for filtering published posts, and accessors/mutators for date formatting Create Category model with posts relationship (belongsToMany) Configure User model with posts relationship (hasMany) Add model observers for automatic slug generation and event handling.
Build post create, read, update, delete
Build complete CRUD functionality for blog posts Create PostController using php artisan make:controller PostController --resource Implement index() to list all published posts with pagination, show() to display single post, create() and store() for creating new posts with validation, edit() and update() for editing posts, destroy() for soft deleting posts Create form requests for validation using php artisan make:request StorePostRequest Build Blade views for listing (index.blade.php), single post (show.blade.php), create/edit forms Add authorization using Laravel policies to ensure only post authors can edit/delete their posts.
Implement user registration and login
Implement authentication system using Laravel Breeze or Laravel UI Run php artisan breeze:install or php artisan ui:auth to scaffold authentication. Customize registration to include additional fields (name, bio, avatar) Set up login, registration, password reset, and email verification flows Create middleware to protect admin routes. Customize auth views to match blog design Set up user profiles with ability to edit profile information Configure email settings in .env for password reset functionality Add remember me functionality and session management.
Integrate TinyMCE or CKEditor
Integrate a rich text editor for post content creation. Choose between TinyMCE or CKEditor and include via CDN or npm package
Configure editor with appropriate toolbar options: headings, bold, italic, lists, links, images, code blocks, blockquotes
Set up image upload handling by creating an upload endpoint in Laravel that stores images in storage/app/public and returns the URL
Configure storage symlink with php artisan storage:link
Add content sanitization to prevent XSS attacks using HTMLPurifier package. Customize editor styling to match blog design. Save content in database as HTML with proper escaping in Blade templates using {!! $content !!}.Image Upload & Featured Images
Add comprehensive image upload and management for blog posts. Install intervention/image package using composer for image manipulation and optimization. Create image upload endpoint in PostController or dedicated ImageController that handles file uploads, validates file type (jpg, png, gif, webp) and size (max 5MB), generates unique filenames using Str::random() or timestamp, stores in storage/app/public/images using Storage facade, creates optimized versions/thumbnails. Configure storage symlink if not already done: php artisan storage:link to make storage/app/public accessible via public/storage. Add featured_image field to posts table migration and Post model fillable array. Create image upload form field in post create/edit Blade templates using <input type="file" accept="image/*">. Implement featured image display in post show view using asset(Storage::url($post->featured_image)). For inline images: integrate image upload button in rich text editor (TinyMCE/CKEditor) that uploads to Laravel endpoint and returns image URL to embed in content. Add image deletion functionality when post is deleted or featured image is replaced using Storage::delete(). Optional: use Laravel Media Library by Spatie for advanced media management with collections, conversions, and responsive images. Optional: integrate cloud storage like AWS S3 or DigitalOcean Spaces by configuring filesystems in config/filesystems.php and .env. Create form request validation for image uploads with rules: 'image|mimes:jpeg,png,jpg,gif,webp|max:5120'.
Testing Your Laravel Blog Application
Configure PHPUnit for Laravel
Set up testing infrastructure for Laravel using PHPUnit (included by default) Configure phpunit.xml with testing database connection (sqlite in memory recommended) Create TestCase base classes if needed Set up database factories using php artisan make:factory for Post, Category, User, and Comment models to generate fake data Create database seeders for consistent test data Configure test environment variables in .env.testing Install additional testing packages like pestphp/pest if preferred Set up test helpers and traits for common testing operations Add test scripts to composer.json for easy execution.
Test homepage renders correctly
Write your first feature test for the blog homepage Create tests/Feature/HomePageTest.php using php artisan make:test HomePageTest Test that the homepage returns successful response (200 status), displays blog title and navigation, shows list of published posts (use factory to create test posts), does not show unpublished posts, includes pagination links if more than 10 posts exist Use Laravel testing assertions like assertSee, assertDontSee, assertViewHas Run tests with php artisan test or vendor/bin/phpunit.
Test post CRUD operations
Write comprehensive feature tests for post CRUD operations Create tests/Feature/PostTest.php Test post creation: authenticated user can create post, validation works (required fields, length limits), slug is auto-generated, timestamps are set Test post reading: guest can view published posts, post shows correct content and author, unpublished posts are hidden from guests Test post updating: only author can update own post, validation works on update, slug is preserved or updated Test post deletion: only author can delete own post, soft delete works, deleted posts are hidden Use RefreshDatabase trait, factories for test data, and actingAs() for authenticated requests.
Test user authentication flows
Write authentication flow tests covering registration, login, logout, and password reset Create tests/Feature/AuthTest.php Test registration: new user can register with valid data, validation prevents invalid registrations, user is logged in after registration, email verification works if enabled Test login: user can login with correct credentials, login fails with wrong credentials, remember me functionality works, rate limiting prevents brute force Test logout: authenticated user can logout, session is cleared Test password reset: user can request reset link, reset email is sent, user can reset password with valid token, token expires Use Laravel authentication testing helpers like assertAuthenticated, assertGuest.
Deploying Your Laravel Blog to Production
Deploy to Laravel Forge or DigitalOcean
Deploy Laravel blog to production If using Laravel Forge: connect your server (DigitalOcean, AWS, etc), create new site, connect Git repository, configure environment variables in Forge dashboard, set up deployment script with composer install, npm build, php artisan migrate, php artisan config:cache If manual deployment: set up server with PHP 8.1+, MySQL/PostgreSQL, Nginx/Apache, install composer, clone repository, copy .env.example to .env and configure production settings, run composer install --optimize-autoloader --no-dev, npm install && npm run build, php artisan key:generate, php artisan migrate --force, set up SSL certificate with Certbot, configure web server to point to public directory, set proper permissions on storage and bootstrap/cache Set up automatic backups for database and storage Configure queue workers and scheduler if used Test all functionality in production.

Add comment functionality