Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alibori/laravel-api-resource-generator
Laravel package to generate API resource for a given Model.
https://github.com/alibori/laravel-api-resource-generator
api-resource generator laravel
Last synced: about 1 month ago
JSON representation
Laravel package to generate API resource for a given Model.
- Host: GitHub
- URL: https://github.com/alibori/laravel-api-resource-generator
- Owner: alibori
- License: mit
- Created: 2023-02-24T09:27:32.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-16T17:23:55.000Z (8 months ago)
- Last Synced: 2024-09-18T02:22:54.746Z (3 months ago)
- Topics: api-resource, generator, laravel
- Language: PHP
- Homepage:
- Size: 125 KB
- Stars: 19
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Laravel API Resource Generator Package
[![Latest Version on Packagist](https://img.shields.io/packagist/v/alibori/laravel-api-resource-generator.svg?style=flat-square)](https://packagist.org/packages/alibori/laravel-api-resource-generator)
![Tests Passed](https://github.com/alibori/laravel-api-resource-generator/actions/workflows/run-tests.yml/badge.svg?event=push)
[![Total Downloads](https://img.shields.io/packagist/dt/alibori/laravel-api-resource-generator.svg?style=flat-square)](https://packagist.org/packages/alibori/laravel-api-resource-generator)This package will help you to generate API resources for your Laravel project.
## Installation
You can install the package via composer:
```bash
composer require alibori/laravel-api-resource-generator --dev
```## Usage
All you need to do is run the following command:
``` bash
php artisan api-resource:generate
```If you want to generate multiple resources at once, you can pass multiple model names separated by a comma:
``` bash
php artisan api-resource:generate ,,
```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
$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:
``` bash
php artisan vendor:publish --provider="Alibori\LaravelApiResourceGenerator\LaravelApiResourceGeneratorServiceProvider" --tag="config"
```