Skip to content

RabibHossain/api-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Total Downloads Latest Stable Version License

Api Action Structure

        app
        └── ApiActionPackages
        │   └── {{ActionName}}   
        │   │   └── Actions
        │   │   │   ├── Create{{ActionName}}
        │   │   │   ├── Delete{{ActionName}}
        │   │   │   ├── Find{{ActionName}}
        │   │   │   ├── List{{ActionName}}
        │   │   │   └── Update{{ActionName}}
        │   │   └── Helpers
        │   │       └── {{ActionName}}Helper
        │   └── BaseHelper
        │   │   └── BaseHelper
        │   └── Traits
        │       └── ApiResponse
        └── Http
        │   └── Controllers
        │   │   └── {{ActionName}}Controller
        │   └── Requests
        │       └── {{ActionName}}Request
        └── Models
        │   └── {{ActionName}}Model
        └── database
            └── migrations
                └── create_{{ActionName}}_table

api-action

Installation

composer require rabibgalib/api-action

Configuration

Add the provider to your config/app.php into provider section if using lower version of laravel,

\Rabibgalib\ApiAction\ApiActionServiceProvider::class,

If you face 419 (page expired) error or CORS or XSRF issue for a new project or have not fixed the issue, then update App/Http/Middleware/VerifyCsrfToken.php as -

  protected $except = [
      "*"
  ];

Run Command

After the installation & configuration run the command as -

  php artisan make:api-action ActionName

Example

If you want to create a Post action api. Please write command as -

  php artisan make:api-action Api/Post

This command will create

  • an API PostController
  • Action directory
    • Action classes
    • Helper classes
    • Trait
  • Form Request
  • Model
  • Migration
    to perform a feature wise service for your application.

api-action-post.PNG

Now put below codes inside Post Model as -

protected $fillable = [
      'author',
      'title',
      'description'
  ];

Now put below codes inside posts Migration as -

$table->string('author')->nullable();
$table->string('title')->nullable();
$table->string('description')->nullable();

After migration command, set up the routes/web.php as -

use App\Http\Controllers\Api\PostController;
Route::get('posts', [PostController::class, 'index']);
Route::post('post', [PostController::class, 'create']);
Route::get('post/{id}', [PostController::class, 'find']);
Route::put('post/{id}', [PostController::class, 'update']);
Route::delete('post/{id}', [PostController::class, 'delete']);

Now, you can test the APIs in Postman or Insomnia easily.

post-api-action.gif

Have fun. Happy Coding.

About

An action API template for laravel development.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages