這是用於眾包項目和問卷的Laravel Web應用程序。
.env文件.env設置在開源許可下提供代碼包括許多好處。其中,與我們的項目相關的是:
ECAS官方安裝
官方安裝
為了清楚起見,設置說明已分為兩個部分:
無論安裝方法如何,您都需要運行以下命令來設置應用程序。
這些命令應在任何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 bash輸入MySQL外殼:
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:seed輸入PHP容器(如果使用Docker組成):
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 Cache:
php artisan config:cache為了將此文件夾與公共目錄鏈接
該應用程序使用社交網站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該應用程序使用Spatie -Laravel Sitemap插件,以創建public/sitemap.xml文件(從git中排除),該文件將被搜索引擎爬行。為了運行當前應用程序安裝的發電機,運行嵌入式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和Prettier來執行代碼風格。
為了運行造型器和格式化,請運行:
npm run lint # this command will check the code style
npm run format # this command will format the code style 該項目使用免費的管理模板。
它還利用Bootstrap 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目錄中定義的,並在getModelClassName方法中由子存儲庫類引用。
因此,我們可以使用在Repository類中定義的基本方法,例如getAll , getById , create , update ,而無需在每個子類中編寫相同的查詢。我們還可以在子類中定義自定義查詢,或者在需要時覆蓋基本方法。
存儲庫類由業務邏輯層類別使用,其中包含業務邏輯,並從控制器到數據訪問層的委託。
有關存儲庫模式的更多信息,請參見此處。
確保您清除了任何緩存和配置文件:
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命令您可以使用php artisan test命令(這是一個內置的Laravel命令)運行測試。
最後,運行測試:
# 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 --coverage通過使用Docker 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 logssystemctl 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。
隨時與項目維護人員聯繫: