承接 alibori/laravel-api-resource-generator 相关项目开发

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

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

alibori/laravel-api-resource-generator

最新稳定版本:v1.4.2

Composer 安装命令:

composer require alibori/laravel-api-resource-generator

包简介

Package to generate API resources from models.

README 文档

README

Latest Version on Packagist Tests Passed Total Downloads

This package will help you to generate API resources for your Laravel project.

Installation

You can install the package via composer:

composer require alibori/laravel-api-resource-generator --dev

Usage

All you need to do is run the following command:

php artisan api-resource:generate <model-name>

If you want to generate multiple resources at once, you can pass multiple model names separated by a comma:

php artisan api-resource:generate <model-name>,<model-name>,<model-name>

This command will generate a new resource for the given model/s name/s with the properties defined in the model.

If you want to set the array keys of the resource as camelCase, you will be prompted to do it.

For example, for the model named User you will get the following resource:

<?php

namespace App\Http\Resources;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use JsonSerializable;

/**
 * Resource generated by alibori/laravel-api-resource-generator
 *
 * @property integer $id
 * @property string $name
 * @property string $email
 * @property string $email_verified_at
 * @property string $password
 * @property string $remember_token
 * @property string $created_at
 * @property string $updated_at
 */
class UserResource extends JsonResource
{
     /**
     * Transform the resource into an array.
     *
     * @param  Request  $request
     * @return array|Arrayable|JsonSerializable
     */
    public function toArray($request): array|JsonSerializable|Arrayable
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'email_verified_at' => $this->email_verified_at,
            'remember_token' => $this->remember_token,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at
        ];
    }
}

Publish config file

If you want to publish the config file to change the default namespace for the generated resources and the directory where the resources will be generated, you can run the following command:

php artisan vendor:publish --provider="Alibori\LaravelApiResourceGenerator\LaravelApiResourceGeneratorServiceProvider" --tag="config"

统计信息

  • 总下载量: 2.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固