Skip to content

A comprehensive Laravel 10 practice repository featuring authentication, blog functionality, real-time events, and modern development practices. Perfect for learning Laravel 10 features, implementing best practices, and building production-ready applications. | Laravel 10 Personal Blog

Notifications You must be signed in to change notification settings

aadhar41/laravel10-Blog

Repository files navigation

Laravel 10 Blog - Comprehensive Personal Blog Platform πŸš€

Laravel 10 PHP GitHub License Build Status Code Style

πŸš€ Overview

Laravel 10 Blog is a comprehensive, production-ready personal blog platform built with Laravel 10 that demonstrates modern PHP development practices. This repository serves as both a learning resource and a solid foundation for building your own blog application with advanced features.

Whether you're a Laravel beginner looking to learn the framework or an experienced developer seeking a well-structured blog application, this project provides:

  • Complete authentication system with email verification
  • Rich blog functionality with rich text editing
  • Real-time capabilities using Laravel Events and Broadcasting
  • Modern UI with Bootstrap 5 and Vite
  • API resources for building mobile or frontend applications
  • Testing with PHPUnit
  • Best practices implementation including caching, localization, and security

✨ Key Features

βœ… Complete Authentication System

  • User registration with email verification
  • Login/logout functionality
  • Password reset system
  • Email confirmation workflow

πŸ“ Advanced Blog Functionality

  • Create, read, update, and delete blog posts
  • Rich text editing with Markdown support
  • Image uploads for post thumbnails
  • Tag system for categorization
  • User profiles with avatars

πŸ’¬ Real-time Interaction

  • Live comment updates using Laravel Events
  • Real-time notifications
  • Broadcasted events for instant updates

🌐 Internationalization

  • Multi-language support
  • Locale switching
  • Translatable content

πŸ”’ Security Features

  • CSRF protection
  • Authentication middleware
  • Input validation
  • Secure password handling

πŸ“Š Performance Optimizations

  • Caching with Redis/Memcached
  • Tag-based caching
  • Optimized database queries
  • Asset optimization with Vite

πŸ“± API Resources

  • RESTful API endpoints
  • JSON responses
  • API documentation
  • Rate limiting

πŸ› οΈ Tech Stack

  • Primary Language: PHP 8.1+
  • Framework: Laravel 10
  • Frontend: Bootstrap 5, Vite, SASS
  • Database: MySQL
  • Testing: PHPUnit, Laravel Debugbar
  • Build Tools: Composer, npm, Vite
  • Authentication: Laravel Sanctum
  • Real-time: Laravel Events & Broadcasting
  • Caching: Redis/Memcached
  • Package Manager: Composer

πŸ“¦ Installation

Prerequisites

Before you begin, ensure you have the following installed on your system:

  • PHP 8.1 or higher
  • Composer for dependency management
  • Node.js 16 or higher for frontend assets
  • MySQL or another supported database
  • Git for version control

Quick Start

  1. Clone the repository:

    git clone https://github.com/yourusername/laravel10-blog.git
    cd laravel10-blog
  2. Install PHP dependencies:

    composer install
  3. Install JavaScript dependencies:

    npm install
  4. Set up environment variables:

    cp .env.example .env
    php artisan key:generate
  5. Configure your database in the .env file:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=laravel_blog
    DB_USERNAME=root
    DB_PASSWORD=
  6. Generate application assets:

    npm run dev
  7. Run database migrations:

    php artisan migrate
  8. Seed the database (optional, for sample data):

    php artisan db:seed

Using Docker (Alternative Setup)

For a complete development environment using Docker:

# Start the Docker containers
docker-compose up -d

# Install PHP dependencies
docker-compose exec laravel composer install

# Install JavaScript dependencies
docker-compose exec laravel npm install

# Set up environment
docker-compose exec laravel cp .env.example .env
docker-compose exec laravel php artisan key:generate

# Run migrations
docker-compose exec laravel php artisan migrate

🎯 Usage

Running the Application

Start the development server:

php artisan serve

Or with Docker:

docker-compose up -d

The application will be available at http://localhost:8000.

Accessing the Application

  • Public URL: http://localhost:8000
  • Admin Panel: After registration, you can access the admin features
  • API Documentation: Available at /api/documentation

Creating a Blog Post

  1. Navigate to the "Create Post" page (requires authentication)
  2. Fill in the title, content, and optional thumbnail
  3. Select tags for categorization
  4. Submit the form to create your blog post

Managing Comments

  1. View any blog post to see the comments section
  2. As an authenticated user, you can add comments in real-time
  3. All comments are broadcasted to connected clients

User Profiles

  1. Visit any user's profile page
  2. Edit your profile by updating your avatar and locale preferences
  3. View your blog posts and comments

πŸ“ Project Structure

laravel10-blog/
β”œβ”€β”€ app/                  # Application source code
β”‚   β”œβ”€β”€ Contracts/         # Contracts and interfaces
β”‚   β”œβ”€β”€ Events/           # Event classes
β”‚   β”œβ”€β”€ Facades/          # Facade classes
β”‚   β”œβ”€β”€ Http/             # HTTP controllers, middleware, requests, resources
β”‚   β”œβ”€β”€ Models/           # Eloquent models
β”‚   β”œβ”€β”€ Providers/        # Service providers
β”‚   └── ...
β”œβ”€β”€ config/               # Configuration files
β”œβ”€β”€ database/             # Database migrations and seeds
β”œβ”€β”€ public/               # Publicly accessible files
β”œβ”€β”€ resources/            # Views and assets
β”‚   β”œβ”€β”€ js/               # JavaScript files
β”‚   β”œβ”€β”€ sass/             # SASS stylesheets
β”‚   └── views/            # Blade templates
β”œβ”€β”€ routes/               # Route definitions
β”œβ”€β”€ tests/                # Test cases
β”œβ”€β”€ vendor/               # Composer dependencies
└── ...

πŸ”§ Configuration

Environment Variables

Copy the example environment file and configure it:

cp .env.example .env

Key environment variables to configure:

# Application settings
APP_NAME=Your Blog Name
APP_ENV=local
APP_URL=http://localhost

# Database configuration
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_blog
DB_USERNAME=root
DB_PASSWORD=

# Mail configuration (for email verification)
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025

# Caching
CACHE_DRIVER=redis
REDIS_HOST=127.0.0.1

# Broadcasting (for real-time features)
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=your_app_id
PUSHER_APP_KEY=your_app_key
PUSHER_APP_SECRET=your_app_secret
PUSHER_APP_CLUSTER=mt1

Customization Options

  1. Change the theme: Edit the SASS files in resources/sass/app.scss

  2. Modify the blog layout: Update the Blade templates in resources/views/layouts/

  3. Adjust post settings: Modify the BlogPost model and related controllers

  4. Change authentication behavior: Update the Auth controllers in app/Http/Controllers/Auth/

🀝 Contributing

We welcome contributions from the community! Here's how you can help:

Development Setup

  1. Fork the repository
  2. Create your feature branch:
    git checkout -b feature/AmazingFeature
  3. Install dependencies:
    composer install
    npm install
  4. Run the development server:
    php artisan serve

Code Style Guidelines

  • Follow PSR-12 coding standards
  • Use 4-space indentation
  • Write clear, concise commit messages
  • Include comprehensive tests for new features
  • Follow the existing code structure

Pull Request Process

  1. Create a descriptive title for your pull request
  2. Provide a detailed description of your changes
  3. Reference any related issues
  4. Include screenshots or GIFs if applicable
  5. Ensure all tests pass

πŸ“ License

This project is open-sourced under the MIT License.

See the LICENSE file for more information.

πŸ‘₯ Authors & Contributors

Maintainer: Your Name - Initial work

Contributors: List of contributors

πŸ› Issues & Support

Reporting Issues

If you encounter any problems or have feature requests:

  1. Search existing issues to avoid duplicates
  2. Create a new issue with:
    • Clear description of the problem
    • Steps to reproduce
    • Expected behavior
    • Screenshots or error logs
    • Your environment details

Getting Help

  • Discussions: For general questions and discussions
  • GitHub Issues: For bug reports and feature requests
  • Community: Join our Laravel Discord server

πŸ—ΊοΈ Roadmap

Current Version (v1.0.0)

  • Complete blog functionality
  • Authentication system
  • Real-time features
  • API resources
  • Testing framework

Planned Features

  1. Version 2.0.0

    • User subscriptions and newsletters
    • Advanced analytics dashboard
    • Social media integration
    • Payment gateway for premium content
  2. Version 3.0.0

    • AI-powered content suggestions
    • Advanced SEO optimization
    • Multi-site support
    • Plugin architecture

Known Issues

  • #123 - Mobile responsiveness in comment section
  • #456 - Tag cloud implementation

πŸŽ‰ Getting Started Examples

Creating a Blog Post (API Example)

// Using the API to create a new blog post
$response = Http::post('http://localhost:8000/api/posts', [
    'title' => 'My First Blog Post',
    'content' => '<p>This is the content of my first blog post.</p>',
    'thumbnail' => $filePath,
    'tags' => [1, 2, 3] // Array of tag IDs
], [
    'auth' => ['api_token' => 'your_api_token']
]);

if ($response->successful()) {
    echo 'Blog post created successfully!';
} else {
    echo 'Error: ' . $response->body();
}

Real-time Comment Example

// Listening for new comments in real-time
Echo.channel('comments.' + postId)
    .listen('CommentPosted', (e) => {
        console.log('New comment:', e.comment);
        // Update the UI with the new comment
        appendCommentToUI(e.comment);
    });

Localization Example

// Switching locales in a controller
public function switchLocale($locale)
{
    session()->put('locale', $locale);
    return redirect()->back();
}

πŸ“š Learning Resources

To get the most out of this project, consider exploring these resources:

  1. Laravel Documentation: https://laravel.com/docs/10.x
  2. Laravel News: https://laravel-news.com
  3. Laravel Discord: https://discord.gg/laravel
  4. PHP The Right Way: https://phptherightway.com

πŸ’‘ Tips for Developers

  1. Use Laravel Tinker for quick testing:

    php artisan tinker
  2. Generate boilerplate code with Artisan commands:

    php artisan make:model Post -mcr
    php artisan make:controller PostController --resource
  3. Optimize your queries with Laravel's query builder:

    $posts = BlogPost::with(['comments', 'tags'])->get();
  4. Use Laravel's caching effectively:

    $post = Cache::remember("post-{$id}", 60, function () use ($id) {
        return BlogPost::findOrFail($id);
    });
  5. Implement proper error handling:

    try {
        // Risky operation
    } catch (\Exception $e) {
        Log::error('Error occurred: ' . $e->getMessage());
        abort(500, 'Something went wrong');
    }

Register Page

Register Page

Login Page

Login Page

User Profile

User Profile

User Profile Edit

User Profile Edit

Posts

Posts

Post Create

Post Create

Post Edit

Post Edit

Post View

Post View

🎯 Best Practices Implemented

  1. Repository Pattern: For data access abstraction
  2. Service Layer: For business logic separation
  3. Dependency Injection: Throughout the application
  4. Resource Controllers: For RESTful API endpoints
  5. Policy Authorization: For fine-grained permissions
  6. Event Broadcasting: For real-time updates
  7. Tagged Caching: For efficient cache invalidation
  8. Environment Configuration: For different deployment scenarios

πŸš€ Next Steps

  1. Deploy to production: Using Laravel Forge, Envoyer, or your preferred hosting
  2. Set up monitoring: With Laravel Horizon or similar tools
  3. Implement CI/CD: For automated testing and deployment
  4. Add more features: Based on your specific requirements
  5. Optimize performance: With caching, database indexing, etc.

Join us in building the future of blogging with Laravel! πŸš€

Contribute Star Fork

About

A comprehensive Laravel 10 practice repository featuring authentication, blog functionality, real-time events, and modern development practices. Perfect for learning Laravel 10 features, implementing best practices, and building production-ready applications. | Laravel 10 Personal Blog

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages