ハマログ

株式会社イーツー・インフォの社員ブログ

Laravel5のartisanコマンドの自作

Laravel5でArtisanコマンドを自作する方法について。

Laravelのartisanの自作を書いたのがもう2年前のことでした!時が立つのは早いものです。
Laravel5では作り方がちょっとだけ変わりました。

How to

Laravel5のコマンドをつくるときは、自分でクラスを作成してもよいのですが専用のコマンドが用意されているので実行します。
コマンドはmake:console.

ヘルプ

> php artisan  help make:console
Usage:
 make:console [--command[="..."]] name

Arguments:
 name                  The name of the command.

Options:
 --command             The terminal command that should be assigned. (default: "command:name")
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message

作ってみました。

> php artisan make:command PostSecurityInformation
Command created successfully.

ジャーン!app/console/Commandsにできました。

20150605 233458

コンソールから呼び出せるようにするために、app/console/Kernel.phpにコマンドを登録します。

protected $commands = [
    'App\Console\Commands\Inspire',
    'App\Console\Commands\PostSecurityInformation' // 
];

もういちどartisan

> php artisan
(略)
post
 post:security        Command description.

Laravel5ではcronライクなスケジューラができたり、ますますコマンドが便利になっています。

artisanLaravelLaravel5PHP

  kaneko tomo   2015年4月20日


関連記事

LaravelのModel Serializationをためしてみる

LaravelのEloquent Modelには、モデルクラスのオブジェクトをJ…

Glassfish を Eclipse にserver登録して ClassNotFoundException が起こる

Glassfish を Eclipse にserver登録しました そのあと G…

Windowsで特定のポートを使用しているアプリケーションを探す

こんにちは、かねこです。 はじめに アプリケーション開発や環境構築をしていて、W…


← 前の投稿

次の投稿 →