นี่คือเว็บแอปพลิเคชัน Laravel สำหรับโครงการและแบบสอบถามแบบ crowdsourcing
.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 คุณจะต้องสร้างฐานข้อมูลสำหรับแอปพลิเคชัน
ในกรณีของสภาพแวดล้อม Docker ให้ป้อน crowdsourcing_platform_db คอนเทนเนอร์และสร้างฐานข้อมูลชื่อ crowdsourcing_db_docker :
docker exec -it crowdsourcing_platform_db bashป้อน MySQL Shell:
mysql -u root -pจากนั้นเรียกใช้คำสั่ง mysql ต่อไปนี้:
CREATE DATABASE IF NOT EXISTS crowdsourcing_db_docker;ก่อนอื่นคุณจะต้องป้อนคอนเทนเนอร์ DB:
docker exec -it crowdsourcing_platform_db bashหากคุณมีไฟล์ Dump 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 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)โดยค่าเริ่มต้นรูปภาพจะถูกเก็บไว้ที่แอพ/ที่เก็บข้อมูล/สาธารณะ วิ่ง
php artisan storage:link.env จากนั้นยังคงมีการตั้งค่า .env ไปที่ Laravel Cache:
php artisan config:cacheเพื่อเชื่อมโยงโฟลเดอร์นี้กับไดเรกทอรีสาธารณะ
แอพนี้ใช้ปลั๊กอิน Socialite Laravel เพื่อจัดการเข้าสู่ระบบโซเชียล
เพื่อให้มันทำงานในสภาพแวดล้อมการพัฒนาของคุณคุณต้องตรวจสอบให้แน่ใจว่าคุณมีคีย์ API และความลับสำหรับ Facebook และ Twitter (คู่มือที่นี่และที่นี่) และคุณสามารถเข้าถึง https: //dev.crowdsourcing/ (สังเกต https) บนเครื่องของคุณ
คำแนะนำสำหรับการเปิดใช้งาน HTTPS บนเครื่องในเครื่องของคุณสามารถพบได้ที่นี่
โดยพื้นฐานแล้วคุณต้องวิ่ง
openssl req -new -sha256 -newkey rsa:2048 -nodes
-keyout dev.crowdsourcing.key -x509 -days 365
-out dev.crowdsourcing.crtอ้างอิง 2 ไฟล์ที่สร้างขึ้นในไฟล์กำหนดค่า NGINX ของแอปพลิเคชัน ตรวจสอบให้แน่ใจว่าคุณเปลี่ยนพอร์ตเป็น 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 Pint เพื่อดำเนินการสไตล์รหัส
เพื่อที่จะเรียกใช้ Styler ให้ Run:
./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 เพื่อดำเนินการสไตล์รหัส
เพื่อที่จะเรียกใช้ Styler & Formatter ให้รัน:
npm run lint # this command will check the code style
npm run format # this command will format the code style โครงการนี้ใช้เทมเพลต adminlte ฟรี
นอกจากนี้ยังใช้ประโยชน์จาก bootstrap 4
แอปพลิเคชันสามารถปรับแต่งและเป็นส่วนตัวสำหรับการติดตั้งแต่ละครั้ง ในไฟล์ .env คุณสามารถตั้งค่าตัวแปร INSTALLATION_RESOURCES_DIR ได้ตามลำดับ ตัวแปรนี้จะต้องใช้ค่าที่แสดงถึงชื่อไดเรกทอรีในไดเรกทอรี resourcess/views/home/partials ตัวอย่างเช่นดูไดเรกทอรี resourcess/views/home/partials/together ไดเรกทอรีนี้จะต้องมีไฟล์ใบมีดบางส่วนสำหรับการติดตั้ง
ส่วนนี้ของเอกสารนี้อธิบายโครงสร้างไดเรกทอรีของแอปพลิเคชัน 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 โดยไม่ต้องเขียนคำค้นหาเดียวกันในแต่ละชั้นเด็ก นอกจากนี้เรายังสามารถกำหนดคิวรีที่กำหนดเองในชั้นเรียนเด็กหรือแทนที่วิธีพื้นฐานหากจำเป็น
คลาสที่เก็บจะถูกใช้โดยคลาส Logic Layer Business ซึ่งมีตรรกะทางธุรกิจและมอบหมายจากคอนโทรลเลอร์ไปยังชั้นการเข้าถึงข้อมูล
ข้อมูลเพิ่มเติมเกี่ยวกับรูปแบบที่เก็บสามารถพบได้ที่นี่
ตรวจสอบให้แน่ใจว่าคุณได้ล้างไฟล์แคชและกำหนดค่าใด ๆ :
php artisan cache:clear
php artisan config:clearสร้างไฟล์ฐานข้อมูลทดสอบ:
touch storage/database_testing.sqliteให้สิทธิ์ที่จำเป็นแก่ไฟล์ฐานข้อมูลทดสอบ:
chmod 777 storage/database_testing.sqliteจากนั้นตรวจสอบให้แน่ใจว่าคุณได้ตั้งค่าฐานข้อมูลทดสอบ:
เรียกใช้การย้ายถิ่นและ seeders สำหรับฐานข้อมูลทดสอบ:
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 ซึ่งเป็น wrapper รอบคำสั่ง phpunit
chmod +x run-tests.sh
./run-tests.sh นอกจากนี้ยังสามารถใช้อาร์กิวเมนต์ใด ๆ (เช่น --filter หรือ --coverage ) ที่คุณจะส่งผ่านไปยังคำสั่ง phpunit
./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 เพื่อเข้าสู่คอนเทนเนอร์ PHPphp 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.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
อย่าลังเลที่จะติดต่อผู้ดูแลโครงการ: