0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel用パッケージの作成方法

Last updated at Posted at 2023-08-14

こんにちは。記事をご覧いただきありがとうございます。

composerでインストールできるLaravel用ライブラリを作成してみたのでその備忘録です。
誰かのお役に立てれば幸いです。

パッケージテンプレート

テンプレート

2.以降で紹介するパッケージのベースとなるテンプレートを作成しました。
よければ使ってください。
https://github.com/ikepu-tp/package

開発環境

開発環境となるものも作りました。
https://github.com/ikepu-tp/create-packages

  • Laravel/Breeze導入済み
  • MySQLのDocker設定済み

1. Laravelのインストール

curl -s https://laravel.build/create-library | bash
cd create-library && ./vendor/bin/sail up

2. リポジトリの作成

mkdir packages/package-name/src
cd packages/package-name
vim composer.json

3. composer.jsonの作成

{
    "name": "ikepu-tp/package-name",
    "description": "",
    "type": "library",
    "keywords": [
        "laravel"
    ],
    "homepage": "****",
    "support": {
        "issues": "https://github.com/ikepu-tp/package-name/issues",
        "source": "https://github.com/ikepu-tp/package-name"
    },
    "require": {
        "php": "^8.2",
        "laravel/framework": "^10.8"
    },
    "license": "MIT",
    "autoload": {
        "psr-4": {
            "ikepu_tp\\PackageName\\": "./src/"
        }
    },
    "authors": [
        {
            "name": "****",
            "email": "****"
        }
    ],
    "extra": {
        "laravel": {
            "providers": [
                "ikepu_tp\\PackageName\\PackageNameServiceProvider"
            ]
        }
    }
}

4. Providerの作成

./vendor/bin/sail artisan make:provider ShorterUrlServiceProvider

src下にShorterUrlServiceProviderを移動する。

5. composer update

composer update

6. GitHubのリポジトリ作成

7. GitHubに公開

cd packages/package-name
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/***/***.git
git push -u origin main

8. Packagistに登録

Packagistにおいて

  1. ユーザー登録をする
  2. Githubと連携する
  3. submitからGithubのURLを入力し,登録する

参考

https://hirossyi.work/blog/116

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?