πŸ—“️ Day 3 at ENATS

 muhalvin.medium.com/lara...

Hello everyone and welcome! πŸ‘‹

Here’s a detailed and organized update on my third day at ENATS, building out API endpoints with token-based authentication πŸš€

Date: Wednesday, June 18, 2025


Morning Sessions

  • Arrived at 9:30 AM and carried forward the API work from yesterday.

  • Focused on authentication routes located in routes/api.php.

  • Thoroughly tested routes both with and without a token, ensuring correct responses.

  • All authentication logic resides in my AuthController.


πŸ”„ CRUD API Routes Implemented

Following successful authentication testing, I created several essential endpoints:

Endpoint Method Functionality
/post GET Fetch all blog posts of an authenticated user
/post POST Create a new post (authentication required)
/post/{id} GET Retrieve a specific post
/post/update/{id} PUT Update a specific post
/post/{id} DELETE Delete a specific post

Afternoon: Testing & Fixes

  • Rigorous testing on each route using Postman.

  • Encountered several issues during method implementation.

  • Debugged and resolved routing bugs and controller logic mishaps.

  • Made updates to internal controller files and API Resource handling.


πŸŒ™ Evening Wrap-Up

  • Successfully built and tested the full authentication system.

  • All CRUD operations for Post are functional and secured.

  • Finalized the first version of the API; ready to build more features tomorrow.


πŸ“Œ Key Takeaways & Resources

  1. Laravel Sanctum provides a lightweight method for token-based API authentication. The typical flow:

    • Install Sanctum, publish config, migrate.

    • Add HasApiTokens to the User model.

    • Use auth:sanctum middleware to protect routes.

  2. Protecting routes:

    Route::middleware('auth:sanctum')->group(function() {
        Route::resource('posts', PostController::class);
    });
    


πŸ’‘ Ask Me Anything

Curious about how I approached authentication, token validation, or debugging?
Drop your questions below—I’d love to dive deeper into any part of the setup!



Comments

Popular Posts