Readouble

Laravel 5.0 Artisanコマンドライン

イントロダクションIntroduction

Artisan(アーティザン:職人)とは、Laravelを構成しているコマンドラインインターフェイスの名前です。アプリケーション開発で役立つ、数多くのコマンドを用意しています。パワフルなSymfonyコンソール・コンポーネントを利用し動いています。Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.

使用法Usage

使用可能な全コマンドの一覧Listing All Available Commands

使用可能なコマンドのリストを全部表示するには、listコマンドを使用してください。To view a list of all available Artisan commands, you may use the list command:

php artisan list

コマンドのヘルプ表示Viewing The Help Screen For A Command

全てのコマンドは「ヘルプ」が用意されており、説明と使用できる引数、オプションを表示します。ヘルプを表示するには、helpに続いてコマンド名を入力してください。Every command also includes a "help" screen which displays and describes the command's available arguments and options. To view a help screen, simply precede the name of the command with help:

php artisan help migrate

設定環境の指定Specifying The Configuration Environment

コマンドを実行する設定環境を指定するには、--envスイッチを使用します。You may specify the configuration environment that should be used while running a command using the --env switch:

php artisan migrate --env=local

現在のバージョンの表示Displaying Your Current Laravel Version

インストールしているLaravelのバージョンを確認するには、--versionオプションを指定します。You may also view the current version of your Laravel installation using the --version option:

php artisan --version

コマンド外からの呼び出しCalling Commands Outside Of CLI

ArtisanコマンドをCLI外部から実行したいこともあります。例えば、HTTPルートからArtisanコマンドを起動したい時です。Artisanファサードを使用するだけです。Sometimes you may wish to execute an Artisan command outside of the CLI. For example, you may wish to fire an Artisan command from an HTTP route. Just use the Artisan facade:

Route::get('/foo', function()
{
	$exitCode = Artisan::call('command:name', ['--option' => 'foo']);

	//
});

Artisanコマンドをキューに入れれば、キューワーカーにより、バックグラウンドで実行されます。You may even queue Artisan commands so they are processed in the background by your queue workers[/docs/{{version}}/queues]:

Route::get('/foo', function()
{
	Artisan::queue('command:name', ['--option' => 'foo']);

	//
});

ArtisanコマンドスケジューラーScheduling Artisan Commands

今まで開発者は、コンソールコマンドを一つ一つスケジュールするために、Cronエントリーを毎回作成してきました。しかし、これは悩みの種でした。コンソールの実行スケジュールは、ソース管理されていませんでしたし、Cronのエントリを追加するため、その都度SSHでサーバーに接続する必要がありました。人生をより簡単に生きましょう。Laravelコマンドスケジューラーを使い、サーバーにCronエントリーを一つ追加するだけで、他に何も用意しなくてもLaravelだけで、コマンド実行スケジュールをスラスラと記述的に定義することができます。In the past, developers have generated a Cron entry for each console command they wished to schedule. However, this is a headache. Your console schedule is no longer in source control, and you must SSH into your server to add the Cron entries. Let's make our lives easier. The Laravel command scheduler allows you to fluently and expressively define your command schedule within Laravel itself, and only a single Cron entry is needed on your server.

コマンドスケジュールは、app/Console/Kernel.phpファイルに記述します。このクラスの中に、scheduleメソッドが見つかるでしょう。始めやすいように、このメソッドの中に簡単な例を準備してあります。好きなだけジョブスケジュールをScheduleオブジェクトに追加してください。唯一以下のCronエントリーだけ、サーバーに追加してください。Your command schedule is stored in the app/Console/Kernel.php file. Within this class you will see a schedule method. To help you get started, a simple example is included with the method. You are free to add as many scheduled jobs as you wish to the Schedule object. The only Cron entry you need to add to your server is this:

* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1

このCronエントリは、Laravelコマンドスケジューラーを毎分呼び出します。それにより、Laravelはスケジュールされているジョブを評価し、実行する必要のあるジョブを起動します。これ以上簡単にできません!This Cron will call the Laravel command scheduler every minute. Then, Laravel evaluates your scheduled jobs and runs the jobs that are due. It couldn't be easier!

スケジュール例More Scheduling Examples

他のスケジュール例をご覧ください。Let's look at a few more scheduling examples:

クロージャーによるスケジュールScheduling Closures

$schedule->call(function()
{
	// タスクを行う…

})->hourly();

端末コマンドのスケジュールScheduling Terminal Commands

$schedule->exec('composer self-update')->daily();

Cronの記述法により指定Manual Cron Expression

$schedule->command('foo')->cron('* * * * *');

一定間隔の繰り返しFrequent Jobs

$schedule->command('foo')->everyFiveMinutes();

$schedule->command('foo')->everyTenMinutes();

$schedule->command('foo')->everyThirtyMinutes();

毎日行うジョブDaily Jobs

$schedule->command('foo')->daily();

24時間制で時間を指定し、毎日行うジョブDaily Jobs At A Specific Time (24 Hour Time)

$schedule->command('foo')->dailyAt('15:00');

一日に2回行うジョブTwice Daily Jobs

$schedule->command('foo')->twiceDaily();

ウィークデーに行うジョブJob That Runs Every Weekday

$schedule->command('foo')->weekdays();

週毎に行うジョブWeekly Jobs

$schedule->command('foo')->weekly();

// 曜日(0から6)と時間を指定する週間スケジュール
$schedule->command('foo')->weeklyOn(1, '8:00');

月毎に行うジョブMonthly Jobs

$schedule->command('foo')->monthly();

特定の曜日に実行するジョブJob That Runs On Specific Days

$schedule->command('foo')->mondays();
$schedule->command('foo')->tuesdays();
$schedule->command('foo')->wednesdays();
$schedule->command('foo')->thursdays();
$schedule->command('foo')->fridays();
$schedule->command('foo')->saturdays();
$schedule->command('foo')->sundays();

ジョブの多重起動を防ぐPrevent Jobs From Overlapping

デフォルトでは、以前の同じジョブが起動中であっても、スケジュールされたジョブは実行されます。これを防ぐには、withoutOverlappingメソッドを使用してください。By default, scheduled jobs will be run even if the previous instance of the job is still running. To prevent this, you may use the withoutOverlapping method:

$schedule->command('foo')->withoutOverlapping();

この例で、fooコマンドは起動していない限り、毎分実行されます。In this example, the foo command will be run every minute if it is not already running.

ジョブを実行する環境の指定Limit The Environment The Jobs Should Run In

$schedule->command('foo')->monthly()->environments('production');

アプリケーションがメンテナンスモードでも実行することを指定Indicate The Job Should Run Even When Application Is In Maintenance Mode

$schedule->command('foo')->monthly()->evenInMaintenanceMode();

コールバックの結果がTrueの時だけジョブを実行Only Allow Job To Run When Callback Is True

$schedule->command('foo')->monthly()->when(function()
{
	return true;
});

スケジュールしたジョブの出力をメール送信E-mail The Output Of A Scheduled Job

$schedule->command('foo')->sendOutputTo($filePath)->emailOutputTo('foo@example.com');

注意: メール送信する前に、予めファイルへ出力を書き出しておく必要があります。Note: You must send the output to a file before it can be mailed.

ジョブの出力を指定したファイルへ書き出しSend The Output Of The Scheduled Job To A Given Location

$schedule->command('foo')->sendOutputTo($filePath);

ジョブを実行後に指定したURLへPingPing A Given URL After The Job Runs

$schedule->command('foo')->thenPing($url);

thenPing($url)の機能を利用するにはGuzzle HTTPライブラリーが必要です。Guzzle 5をプロジェクトに追加するには、composer.jsonファイルへ以下の行を追加してください。Using the thenPing($url) feature requires the Guzzle HTTP library. You can add Guzzle 5 to your project by adding the following line to your composer.json file:

"guzzlehttp/guzzle": "~5.0"

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作