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.
- 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.
-
Clone the repository:
git clone https://github.com/I3rixon/blog-test-laravel.git cd blog
-
Install dependencies:
composer install
-
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=
-
Run migrations:
php artisan migrate
-
Generate the application key:
php artisan key:generate
-
Run the development server:
php artisan serve
-
Post:
title
: stringcontent
: texttimestamps
-
Comment:
content
: textpost_id
: foreign key
Run migrations with:
php artisan migrate
-
PostController:
index
: View all postsshow
: View a single postcreate
: Show the create post formstore
: Save a new postedit
: Edit a postupdate
: Update a postdestroy
: Delete a post
-
CommentController:
store
: Add a comment to a post
Route::resource('posts', PostController::class);
Route::post('posts/{post}/comments', [CommentController::class, 'store'])->name('comments.store');
-
Install Sanctum:
composer require laravel/sanctum
-
Run migrations:
php artisan migrate
-
API Endpoints:
POST /api/login
GET /api/posts
GET /api/posts/{id}
POST /api/posts/{id}/comments
-
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
This project is open-source and available under the MIT License.
Here are some screenshots of the project:
API request via Postman example
Searching