【Laravel】artisanのstub:publishコマンドを解説

Laravel artisan

artisanコマンド一覧 チートシートへ戻る

Laravel 10.x以降のartisanの「session:table」コマンドを解説します。

Description

カスタマイズ可能なすべてのスタブを公開

artisanコマンドで作成されるテンプレートをstubディレクトリに出力します。

Usage

php artisan stub:publish [--existing] [--force]
Bash

Arguments

オプションはありません。

Options

オプション省略形必須説明
existing--stubs/以下にあるファイルのみ上書き出力
force--既存のファイルを上書き

Example

no options

php artisan stub:publish
Bash
   INFO  Stubs published successfully.  
Bash
$ ls stubs/
cast.inbound.stub          controller.nested.api.stub            enum.stub                   mail.stub                   notification.stub    resource-collection.stub
cast.stub                  controller.nested.singleton.api.stub  event.stub                  markdown-mail.stub          observer.plain.stub  resource.stub
class.invokable.stub       controller.nested.singleton.stub      factory.stub                markdown-notification.stub  observer.stub        rule.stub
class.stub                 controller.nested.stub                job.queued.stub             middleware.stub             pest.stub            scope.stub
console.stub               controller.plain.stub                 job.stub                    migration.create.stub       pest.unit.stub       seeder.stub
controller.api.stub        controller.singleton.api.stub         listener.queued.stub        migration.stub              policy.plain.stub    test.stub
controller.invokable.stub  controller.singleton.stub             listener.stub               migration.update.stub       policy.stub          test.unit.stub
controller.model.api.stub  controller.stub                       listener.typed.queued.stub  model.pivot.stub            provider.stub        trait.stub
controller.model.stub      enum.backed.stub                      listener.typed.stub         model.stub                  request.stub         view-component.stub
Bash

existing

既にstubs以下にあるファイルのみをLaravelデフォルトのもので上書きします。

php artisan stub:publish --existing
Bash
   INFO  Stubs published successfully.  
Bash
$ ls stubs/
test.stub

$ cat stubs/test.stub 
HOGE

$ php artisan stub:publish --existing

   INFO  Stubs published successfully.  

$ ls stubs
test.stub

$ cat stubs/test.stub 
<?php

namespace {{ namespace }};

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

class {{ class }} extends TestCase
{
    /**
     * A basic feature test example.
     */
    public function test_example(): void
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}
Bash

Follow me!

\このブログが役に立ったらサポートお願いします/

Follow me!

artisanLaravelPHP
スポンサーリンク
千原 耕司をフォローする

コメント

PAGE TOP
タイトルとURLをコピーしました