承接 rabibgalib/api-action 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rabibgalib/api-action

最新稳定版本:v1.0.1

Composer 安装命令:

composer require rabibgalib/api-action

包简介

This packages will help to create APIs with Controller, Request, Traits, Model, Migration, Action Classes, Helper Class.

README 文档

README

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.

统计信息

  • 总下载量: 28
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-10