これは、クラウドソーシングプロジェクトやアンケート向けのLaravel Webアプリケーションです。
.envファイルを作成します.env設定をキャッシュしますオープンソースライセンスの下でコードを提供するには、多くの利点があります。それらのうち、私たちのプロジェクトに関連するものは次のとおりです。
ECAS公式インストール
公式のインストールをscify
セットアップの指示は、明確にするために2つのセクションに分割されています。
インストール方法に関係なく、アプリケーションをセットアップするには、次のコマンドを実行する必要があります。
これらのコマンドは、Dockerコンテナの外で実行する必要があります。
sudo chown -R ` whoami ` :www-data storage
chmod 775 storage
cd storage/
find . -type f -exec chmod 664 {} ;
find . -type d -exec chmod 775 {} ;インストール方法に応じて、Dockerコンテナまたはローカルマシンで残りの手順を実行する必要があります。
注: Docker Composeを使用している場合、最初にPHPコンテナを入力するには最初に必要です。
docker exec -it crowdsourcing_platform_server bashそして、残りのコマンドを実行します。
ローカルマシンでコマンドを実行している場合は、次のコマンドを直接実行できます。
DDEVを開始した場合は、 ddev execを使用したすべてのコマンドを実行する必要があります。
.envファイルを作成しますプロジェクトをクローニングした後、.envファイルを作成します(.env.exampleのコピーである必要があります):
cp .env.example .envドッカー以外のインストールの場合、アプリケーション用のデータベースを作成する必要があります。
Docker環境の場合、 crowdsourcing_platform_dbコンテナを入力し、 crowdsourcing_db_dockerという名前のデータベースを作成します。
docker exec -it crowdsourcing_platform_db bashMySQLシェルを入力してください:
mysql -u root -p次に、次のMySQLコマンドを実行します。
CREATE DATABASE IF NOT EXISTS crowdsourcing_db_docker;まず、DBコンテナを入力する必要があります。
docker exec -it crowdsourcing_platform_db bash既存のMySQLダンプファイルがある場合は、現在のディレクトリにあることを確認し、データベースにインポートしてください。
mysql -u root -p crowdsourcing_db_docker < dump.sql次に、 .envファイルに次のものを追加します。
DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=crowdsourcing_db_docker
DB_USERNAME=root
DB_PASSWORD=root注: Docker Composeを使用している場合は、サーバーコンテナを入力するには最初に必要です。
docker exec -it crowdsourcing_platform_server bashphp artisan migratephp artisan db:seedPHPコンテナを入力します(Docker Composeを使用している場合):
docker exec -it crowdsourcing_platform_server bash次に、次のコマンドを実行します。
composer install
composer dump-autoloadphp artisan key:generatenpm install
npm run dev # (if in development mode, use for live changes)
npm run build # (if in development mode)
npm run prod # (if in production mode)デフォルトでは、画像はApp/Storage/Publicに保存されます。走る
php artisan storage:link.env設定をキャッシュしますそして、 .env設定をlaravelキャッシュに保持します。
php artisan config:cacheこのフォルダーをパブリックディレクトリにリンクするために
このアプリは、Socialite Laravelプラグインを使用してソーシャルログインを処理します。
開発環境で機能させるには、FacebookとTwitterのAPIキーとシークレット(こちらとこちら)の秘密があることを確認し、https://dev.crowdsourcing/(httpsに注意)にアクセスできるようにする必要があります。
ローカルマシンでHTTPを有効にするためのガイドは、こちらをご覧ください。
基本的に、実行する必要があります
openssl req -new -sha256 -newkey rsa:2048 -nodes
-keyout dev.crowdsourcing.key -x509 -days 365
-out dev.crowdsourcing.crtアプリケーションのnginx構成ファイルに生成された2つのファイルを参照してください。以下に示すように、ポートを443に変更してください。
server {
listen 443 ssl;
server_name dev.crowdsourcing;
ssl_certificate /path/to/dev.crowdsourcing.crt;
ssl_certificate_key /path/to/dev.crowdsourcing.key;
root /var/www/crowdsourcing/public;
add_header X-Frame-Options "SAMEORIGIN" ;
add_header X-XSS-Protection "1; mode=block" ;
add_header X-Content-Type-Options "nosniff" ;
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;
location / {
try_files $uri $uri / /index.php? $query_string ;
}
location = /favicon.ico { access_log off ; log_not_found off ; }
location = /robots.txt { access_log off ; log_not_found off ; }
error_page 404 /index.php;
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
}
location ~ /.ht {
deny all ;
}
}また、実行して、必ずNginxを再起動してください
sudo systemctl restart nginxこのアプリケーションでは、 public/sitemap.xmlファイル(GITから除外)を作成するために、Spatie -Laravel SiteMapプラグインを使用します。現在のアプリケーションインストールのためにジェネレーターを実行するには、埋め込みlaravelコマンドを実行します。
php artisan sitemap:generateこのアプリケーションは、コードスタイルを実行するためにLaravelパイントを使用します。
スタイラーを実行するために、実行してください:
./vendor/bin/pint --test -v # the --test will not do any changes, it will just output the changes needed
./vendor/bin/pint -v # this command will actually perform the code style changes このアプリケーションでは、コードスタイルを実行するためにEslintとよりきれいを使用します。
Styler&Formatterを実行するには、実行してください。
npm run lint # this command will check the code style
npm run format # this command will format the code style このプロジェクトでは、無料のadminlteテンプレートを使用します。
また、ブートストラップ4を使用します
アプリケーションは、インストールごとに調整およびパーソナライズできます。 .envファイルでは、それに応じてINSTALLATION_RESOURCES_DIR変数を設定できます。この変数はresourcess/views/home/partialsディレクトリのディレクトリ名を表す値を取得する必要があります。たとえば、 resourcess/views/home/partials/together Directoryを参照してください。このディレクトリには、インストール用の部分的なブレードファイルが含まれている必要があります。
ドキュメントのこの部分では、Laravelアプリケーションのディレクトリ構造について説明します。
主に、アプリケーションで使用されるカスタムディレクトリとファイルにスコープされています。一般的なLaravelディレクトリ構造については、公式ドキュメントを参照してください。
├── app # Laravel application directory
│ ├── BusinessLogicLayer # Business Logic Layer classes (services that contain the business logic and delegate from Controllers towards the Data Access Layer)
│ ├── Http/Controllers # Controllers directory (classes that handle the HTTP requests, perform the necessary validations/operations and return the responses)
│ ├── Http/Middleware # Middleware directory (classes that handle the HTTP requests before they reach the Controllers)
│ ├── Models # Models directory (ORM classes that represent the database tables and contain the relationships between them)
│ ├── Notifications # Notifications directory (classes that handle the notifications, like emails)
│ ├── ViewModels # View Models directory (classes that contain the data that will be passed to the views)
│ ├── Repository # Repository directory (classes that handle the database operations and contain the DB/ORM queries)
│ resources # Resources directory (contains the views, assets, front-end files, and other resources)
│ ├── views # Views directory (contains the blade files that are used to render the HTML)
│ ├── assets # Assets directory (contains the front-end assets like CSS, JS, images, etc.)
│ ├── js # JavaScript files (contains the Vue.js components and other JS files)
│ ├── sass # SASS files (contains the SASS files that are compiled to CSS)
│ ├── lang # Language files (contains the language files for the translations)
アプリケーションは、リポジトリパターンを使用して、ビジネスロジックをデータアクセスロジックから分離します。
すべてのデータベース操作は、DB/ORMクエリを含むリポジトリクラスによって処理されます。
これらのクラスはapp/Repositoryディレクトリにあり、すべてapp/Repository/Repositoryクラスを拡張します。
各チャイルドクラスはデータベーステーブル/エンティティを表し、そのテーブルのクエリが含まれています。このエンティティは、 app/Models Directoryで定義されており、 getModelClassNameメソッドのChild Repositoryクラスで参照されます。
したがって、各子供クラスで同じクエリを書くことなく、 getAll 、 getById 、 create 、 updateなど、 Repositoryクラスで定義されているベースメソッドを使用できます。また、子クラスのカスタムクエリを定義したり、必要に応じてベースメソッドをオーバーライドすることもできます。
リポジトリクラスは、ビジネスロジックレイヤークラスで使用されます。ビジネスロジックレイヤークラスには、ビジネスロジックとコントローラーからデータアクセスレイヤーに委任します。
リポジトリパターンの詳細については、こちらをご覧ください。
キャッシュと構成ファイルをクリアしていることを確認してください。
php artisan cache:clear
php artisan config:clearテストデータベースファイルを作成します。
touch storage/database_testing.sqliteテストデータベースファイルに必要な権限を指定します。
chmod 777 storage/database_testing.sqlite次に、テストデータベースを設定していることを確認してください。
テストデータベースの移行とシーダーを実行します。
php artisan migrate:fresh --seed --env=testing --database=sqlite_testingphp artisan testコマンドを備えたPHPunit内蔵のLaravelコマンドであるphp artisan testコマンドを使用して、テストを実行できます。
そして最後に、テストを実行します。
# Note that you filter the tests by using the --filter flag (without the = sign)
php artisan test --env=testing --filter {METHOD OR CLASS NAME} --coveragerun-tests.shスクリプトでテストを実行しますまた、 run-tests.shスクリプトを使用してテストを実行することもできます。これは、phpunitコマンドの周りのラッパーです。
chmod +x run-tests.sh
./run-tests.shこれは、PHPunitコマンドに渡すという引数( --filterまたは--coverageフラグなど)を取得することもできます。
./run-tests.sh --filter {METHOD OR CLASS NAME}または
./run-tests.sh --coverageDocker Composeを使用することにより、次の手順に従ってアプリケーションをデバッグできます。
docker compose upしてコンテナを起動します。.vscode/launch.jsonファイルがあることを確認してください。 {
"version" : " 0.2.0 " ,
"configurations" : [
{
"name" : " Listen for Xdebug " ,
"type" : " php " ,
"request" : " launch " ,
"port" : 9003 ,
"pathMappings" : {
"/var/www" : " ${workspaceFolder} "
},
"log" : true
}
]
}これで、アプリケーションのデバッグを開始できます。
テストのデバッグについて:
docker exec -it crowdsourcing_platform_server bashを実行して、phpコンテナを入力します。php artisan app:test --filter {METHOD OR CLASS NAME} 。たとえば、 php artisan app:test --filter authenticatedNonAdminUserCannotAccessCreatePage 。 問題が発生した場合は、次の手順を参照してください。
docker compose logs確認します。systemctl status nginxおよびsystemctl status php-fpmstorage/logs/laravel.logにあるlaravelログを確認します.envファイルに正しいデータベース資格情報があることを確認してくださいsystemctl status mysqlnginx -t アプリケーションに貢献するには、次の手順に従ってください。
git checkout -b <branch_name> 。git commit -m '<commit_message>'git push origin <project_name>/<location>このプロジェクトは、Apacheライセンスバージョン2.0に基づいてライセンスされているオープンソースソフトウェアです。
このプロジェクトは、ScifyとECASによって開発されており、Laravelフレームワークに基づいています。プロジェクトはScifyによって維持されています。
アプリケーションで使用されている画像の一部はFreepikからのものです。
プロジェクトメンテナーにお気軽にお問い合わせください: