Laravel 10.xのartisanの「make:resource」コマンドを解説します。
Description
新しいリソースを作成します。
Usage
php artisan make:resource [-f|--force] [-c|--collection] [--] <name>
Arguments
引数 | 必須 | 設営 |
---|---|---|
name | 必須 | リソース名 |
Options
オプション | 省略形 | 必須 | 説明 |
---|---|---|---|
force | f | - | リソースが既に存在する場合でも、クラスを作成 |
collection | c | - | リソースコレクションを作成する |
Examples
no options
php artisan make:resource FooResource
INFO Resource [app/Http/Resources/FooResource.php] created successfully.
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class FooResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
Stub
Option | Stub file name |
---|---|
- | resource.stub |
collection | resource-collection.stub |
Source
10.x
framework/src/Illuminate/Foundation/Console/ResourceMakeCommand.php at 10.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
11.x
framework/src/Illuminate/Foundation/Console/ResourceMakeCommand.php at 11.x · laravel/framework
The Laravel Framework. Contribute to laravel/framework development by creating an account on GitHub.
コメント