Skip to content

I3rixon/blog-test-laravel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Blog Project

This is a simple blog management system built with Laravel. It includes functionality for creating, editing, viewing, and deleting blog posts, as well as adding comments and searching for posts.

📚 Features

  • CRUD for Blog Posts: Create, update, delete, and view blog posts.
  • Comments: Add comments to posts.
  • Search: Search posts by title.
  • API Support: Endpoints for managing posts and comments.
  • Sanctum Authentication: API token-based authentication.

🚀 Project Setup

  1. Clone the repository:

    git clone https://github.com/I3rixon/blog-test-laravel.git
    cd blog
  2. Install dependencies:

    composer install
  3. Create the .env file and set the database connection:

    cp .env.example .env

    Update the following in .env:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=blog
    DB_USERNAME=root
    DB_PASSWORD=
    
  4. Run migrations:

    php artisan migrate
  5. Generate the application key:

    php artisan key:generate
  6. Run the development server:

    php artisan serve

🛠️ Models & Migrations

  • Post:

    • title: string
    • content: text
    • timestamps
  • Comment:

    • content: text
    • post_id: foreign key

Run migrations with:

php artisan migrate

🎛️ Controllers

  • PostController:

    • index: View all posts
    • show: View a single post
    • create: Show the create post form
    • store: Save a new post
    • edit: Edit a post
    • update: Update a post
    • destroy: Delete a post
  • CommentController:

    • store: Add a comment to a post

🌐 Routes

Route::resource('posts', PostController::class);
Route::post('posts/{post}/comments', [CommentController::class, 'store'])->name('comments.store');

🔐 Sanctum API Authentication

  1. Install Sanctum:

    composer require laravel/sanctum
  2. Run migrations:

    php artisan migrate
  3. API Endpoints:

    • POST /api/login
    • GET /api/posts
    • GET /api/posts/{id}
    • POST /api/posts/{id}/comments
  4. Seed the database with a user:

    php artisan db:seed --class=UserSeeder

    This seeder will create a user with the following credentials:

    Name: root

    Email: [email protected]

    Password: password


✅ License

This project is open-source and available under the MIT License.

Screenshots

Here are some screenshots of the project:

Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4

API request via Postman example

Screenshot 5 Screenshot 6

Searching

Screenshot 7 Screenshot 8

About

Blog with comments test task

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published