1codehappy/laravel-api

This package is abandoned and no longer maintained. No replacement package was suggested.

The Boilerplate for Laravel Restful Apis.


README

CircleCI

A simple, a modern and an elegant Laravel boilerpate for your api, applying Domain Driven Design and hexagonal architecture principles based on Laravel Beyond Crud.

Features

  • PHP 8.1+
  • Laravel 9 Github Docs
  • CircleCI Site
  • Api restful
  • JWT Auth
  • ACL & Laravel Policies
  • PestPHP tests
  • OpenApi docs

Installation

Create your project using composer.

composer create-project 1codehappy/laravel-api myApi

Directories

See the directory structure bellow:

|-- app/
    |-- Backend # Api & Artisan commands
    |-- Domain # Domains
    |-- Support # Commons & Api Documentation

Factories

<?php

$user = User::factory()->hasRoles()->hasPermissions()->create();
$roles = Role::factory()->hasPermissions()->count(2)->create();
$permissions = Permission::factory()->count(3)->create();

$user->assignRole($roles->pluck('name')->all()) # Assign 2 random roles.
  ->givePermissionTo($permissions->pluck('name')->all()) # Give 3 random permissions.
  ->load('roles', 'permissions'); # Load object relations.

Routes

GET /api-docs:

  • Authentication:
    • POST /auth/login: Sign in.
    • POST /auth/logout: Sign out.
    • POST /auth/refresh: Refresh the JWT Token.
  • User's profile:
    • GET /auth/me: Get authenticated user's profile.
    • PUT /auth/me: Edit authenticated user's profile.
    • PUT /auth/me/password: Change authenticated user's password.
  • ACL:
    • GET /permissions: Get the permission list.
    • GET /roles: Get the role list.
    • GET /roles/{uuid}: Get the role.
    • POST /roles: Create a new role.
    • PUT /roles/{uuid}: Edit the role.
    • DELETE /roles/{uuid}: Delete the role.
  • Users:
    • GET /users/: Get the user list.
    • GET /users/{uuid}: Get the user.
    • POST /users: Create a new user.
    • PUT /users/{uuid}: Edit the user.
    • DELETE /users/{uuid}: Delete the user.

Api Documentation

To generate the api documentation:

php artisan l5-swagger:generate # or `composer doc`

PHP Libraries

Composer Scripts

  • composer clear: Clear laravel cache.
  • composer optimize: Optimize api.
  • composer cs: Fix coding style.
  • composer analyse: Run larastan.
  • composer test: Run pestphp.
  • composer sec: Check the php libraries.
  • composer code: Run cs, analyse, test and sec.
  • composer doc: Generate the api documentation.

by CodeHappy ;)