アプリ関連ニュース
- 2022年4月01日
- 技術情報
LaravelでLocalでない場合のhttps対応
今回はhttpでアクセスしようとしてる時発生した問題をどうやって解決できるかを共有したいかなと思います。
Staging環境や本番環境に対応すると、期待した画面が出ず、デザイン・機能が実行していない状態が続きました。
デベロッパーツールから確認すると、httpsではなくhttpでアクセスしようとしてることがわかりました。
ということで、以下のように修正すると、httpsでアクセスできることを確認できます。
web.phpで直接修正
//.env APP_ENV=localでない場合https化
if (config('app.env') === 'production' or config('app.env') === 'staging') {
URL::forceScheme('https');
}
これで再度確認すると、httpsでアクセスでき、画面も機能も動いています。
金曜担当 : Ami
asahi at 2022年04月01日 10:00:00
- 2022年3月31日
- Web Service
Laravelのカスタムパッケージを構築する方法
Packages
パッケージは独立したソースコードで、開発者は composer などのパッケージ管理ツールを使って自分のプロジェクトに取り込むことができます。これらのソースコードは、メインのソースコードとは別にバージョン管理することができ、独自のテストを持ち、独自の依存関係を管理することができます。
多くのプロジェクトがあり、いくつかの機能や特徴が似ている場合、これらの機能をパッケージで実装し始めるとよいでしょう。
Composerは、PHPパッケージの依存関係管理ツールです。各パッケージが必要とするすべての依存関係をベンダディレクトリに 重複させることなく取り込み、パッケージの管理を支援します。
Laravelパッケージの作成
1.新しいLaravelプロジェクトを作成する
Laravelのプロジェクトを作成するために、コマンドラインでComposerを使用します。
composer create-project — prefer-dist laravel/laravel custom-message
2.ファイル構造
新規Laravelプロジェクトのデフォルトフォルダ構造上で、以下のようなファイル構造を作成します。
packages –> custom-simple-package -> custom-message –> src
packages フォルダ内には、ベンダー名 custom-simple-package の後に、パッケージ名 custom-message を記述することに留意してください。src フォルダには、パッケージのすべてのソースコードが格納されます。
3.パッケージcomposer.json
コマンドで、packages/custom-simple-package/custom-message ディレクトリに移動します。次に、以下のコマンドを実行して、このフォルダをcomposerパッケージとして初期化する必要があります。
composer init
初期化が終わったら、composer.json ファイルを編集します。
{
"name": "custom-simple-package/custom-message",
"description": "CustomMessage - A simple Laravel package.",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Mary Blury",
"email": "maryblury@gmail.com"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"CustomSimplePackage\\CustomMessage\\": "src/"
}
},
"require": {}
}
ここで追加されたもので注意すべきは、autoloadオブジェクトプロパティだけです。これは、与えられた名前空間CustomSimplePackgeのCustomMessageで自動的にあなたのパッケージをロードします。
4.プロジェクトcomposer.json
CustomSimplePackageの行を追加して、パッケージの名前空間をオートロードします。”packages/custom-simple-package/custom-message/src” という行を、プロジェクトの composer.json ファイルの autoload->psr-4 プロパティに追加してください。
"autoload": {
"psr-4": {
"App\\": "app/",
"CustomSimplePackage\\CustomMessage\\": "packages/custom-simple-package/custom-message/src"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
プロジェクトの composer.json ファイルを編集したので、プロジェクトのルートディレクトリで次のコマンドを実行して、再読み込みします。
composer dump-autoload
5.CustomMessage.php Class
<?php
namespace CustomSimplePackage\CustomMessage;
class CustomMessage
{
public function greet(String $name)
{
return 'Hello ' . $name . '! How are you doing today?';
}
}
このクラスの名前空間は、プロジェクトの composer.json ファイルで指定した名前空間と同じものを指定して、オートロードされるようにします。
6.パッケージのテスト
これで、シンプルなパッケージがテストできるようになりました。その前に、ルートを作成して、とりあえずこのルートからパッケージのCustomMessageクラスを呼び出してみましょう。
<?php
use CustomSimplePackage\CustomMessage\CustomMessage;
Route::get('/custom-message/{name}', function($name) {
$cMessage = new CustomMessage();
return $cMessage->greet($name);
});
CustomMessage クラスをパッケージからインポートするには、use キーワードで最初に名前空間を指定します。そして、プロジェクトのルートファイル内で、そのクラスのインスタンスを作成し、そのメンバ関数を呼び出すことができます。
プロジェクトのルートディレクトリで、以下のコマンドを実行して、開発サーバーを実行します。
php artisan serve
Laravel development server started: <http://127.0.0.1:8000>
ブラウザを起動し、次のURLを入力します。http://127.0.0.1:8000/custom-message/Mary
ブラウザで見ると、
Hi Mary ! How are you doing today?
7. GitLabへのパッケージの公開
まず、GitLabで新しいプロジェクトを作成しましょう。可視性のレベルが public になっていることを確認しましょう。
パッケージディレクトリpackages/custom-simple-package/custom-messageに移動します。以下のコマンドを実行して、git を初期化し、変更をコミットし、チェンジセットにセマンティックバージョニングのタグを付けます。
// packages/custom-simple-package/custom-message
$ git init
$ git checkout -b master
$ git add .
$ git commit -m "Initial commit"
$ git tag 1.0.0
ローカルのソースコードを新しく作成したGitLabプロジェクトにプッシュするために、次のコマンドを実行します。
// packages/custom-simple-package/custom-message
$ git remote add origin https://gitlab.com/tsuki/custom-message.git
$ git push -u origin --all
$ git push -u origin --tags
これで、準備は万端です。
8.Laravelパッケージのインポート
これで、Composerを使ってGitLabサーバーから新しいLaravelプロジェクトにパッケージをインポートすることができます。ローカルマシンで別の Laravel プロジェクトを作成します。
新しいプロジェクトの composer.json ファイルを編集して、このパッケージを require するようにします。また、GitLab のリポジトリを指定して、Composer がデフォルトの packagist リポジトリ以外にパッケージを取得する場所をわかるようにします。
以下のコマンドを実行し、プロジェクトの composer.json ファイルに加えた変更を読み込み、パッケージをインストールします。
composer update
これで、プロジェクトの vendor ディレクトリにパッケージが見つかるはずです。
By Tsuki
tsuki at 2022年03月31日 10:00:00
- 2022年3月31日
- 技術情報
DataTablesを使用したテーブル生成とサーバーサイド連携(6)
本記事ではDataTablesを使用したテーブル生成方法とサーバーサイド連携方法をシェアします。
今回は前回の記事で説明をおこなったサーバーサイドでのページング処理実装の続きをおこなっていきたいと思います。
nishida at 2022年03月31日 10:00:00
- 2022年3月30日
- 他の話題
AMDの超解像機能を試してみました
tanaka at 2022年03月30日 10:00:00
- 2022年3月29日
- 技術情報
Most used 5 Python Image Processing Libraries
Today, I would like to share about most used image processing libraries in python. Let’s take a look.
OpenCV
First released in 2000, OpenCV has become a popular library due to its ease of use and readability. It is mostly used in computer vision tasks such as object detection, face detection, face recognition, image segmentation, etc.
Scikit-Image
Scikit-Image is a python-based image processing library that has some parts written in Cython to achieve good performance. It is a collection of algorithms for image processing such as:
- Segmentation,
- Geometric transformations,
- Color space manipulation,
- Analysis,
- Filtering,
- Morphology,
- Feature detection
Pillow/PIL
PIL (Python Imaging Library) is an open-source library for image processing in Python. PIL can perform tasks on an image such as reading, rescaling, saving in different image formats. PIL can be used for Image archives, Image processing, Image display.
NumPy
NumPy(Numerical Python) is a open-source Python library for data manipulation and scientific computing. It is used in the domain of linear algebra, Fourier transforms, matrices, and the data science field. NumPy arrays are faster than Python Lists. And an image is essentially an array of pixel values where each pixel is represented by 1 (greyscale) or 3 (RGB) values. So, NumPy can easily perform tasks such as image cropping, masking, or manipulation of pixel values.
Matplotlib
Matplotlib is mostly used for 2D visualizations, but it can also be leveraged for image processing. Matplotlib is effective in altering images for extracting information out of it although it does not support all the file formats.
This is all for now.
Hope you enjoy that.
By Asahi
waithaw at 2022年03月29日 10:00:00