Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
40
Help us understand the problem. What is going on with this article?
@ucan-lab

Laravel開発時に便利なmake(Makefile)コマンド集

2020年最速の記事です😇

Laravel で開発する際、よく実行する docker-compose のように長いコマンドや環境構築時に多数のコマンドを実行する機会が多くあるかと思います。

各個人でalias定義したりshellの補完機能を設定しても良いですが、共有するのは手間です。

そんな時に Makefile を用意しておくと複数のコマンドを一度に実行するようにタスク登録できて便利です。 Makefile をGitで管理しておけば共有もとても楽になります。

make コマンド

$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

make コマンドが使える環境ならokです。

Makefile 使い方

コマンドを実行するディレクトリに Makefile という名前で配置すればokです。

$ make up
# docker-compose up -d # このコマンドが実行される

Makefile 例

参照ファイル: ucan-lab/docker-laravel/Makefile

あくまでも例なので参考程度にしてください。

Makefile
up:
    docker-compose up -d
build:
    docker-compose build
create-project:
    docker-compose up -d --build
    docker-compose exec app composer create-project --prefer-dist laravel/laravel .
    docker-compose exec app composer require predis/predis
install:
    docker-compose up -d --build
    docker-compose exec app composer install
    docker-compose exec app cp .env.example .env
    docker-compose exec app php artisan key:generate
    docker-compose exec app php artisan migrate:fresh --seed
reinstall:
    @make destroy
    @make install
stop:
    docker-compose stop
restart:
    docker-compose down
    docker-compose up -d
down:
    docker-compose down
destroy:
    docker-compose down --rmi all --volumes
ps:
    docker-compose ps
app:
    docker-compose exec app bash
fresh:
    docker-compose exec app php artisan migrate:fresh --seed
seed:
    docker-compose exec app php artisan db:seed
tinker:
    docker-compose exec app php artisan tinker
dump:
    docker-compose exec app php artisan dump-server
test:
    docker-compose exec app php ./vendor/bin/phpunit
cache:
    docker-compose exec app composer dump-autoload -o
    docker-compose exec app php artisan optimize:clear
    docker-compose exec app php artisan optimize
cache-clear:
    docker-compose exec app php artisan optimize:clear
cs:
    docker-compose exec app ./vendor/bin/phpcs
cbf:
    docker-compose exec app ./vendor/bin/phpcbf
db:
    docker-compose exec db bash
sql:
    docker-compose exec db bash -c 'mysql -u $$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE'
node:
    docker-compose exec node ash
npm:
    docker-compose exec node npm install
    docker-compose exec node npm run dev
yarn:
    docker-compose exec node yarn
    docker-compose exec node yarn dev

これをベースに各プロジェクト用のコマンドを追加して使うと良い感じかなと思います。

参考

40
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ucan-lab
Backend Developer at ROLO. I love PHP and I'm focusing on Laravel, Docker, GraphQL.
yyphp
PHPerが毎週集まり、ざっくばらんに情報交換する雑談コミュニティ

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
40
Help us understand the problem. What is going on with this article?