Menu

Showing posts with label framework. Show all posts
Showing posts with label framework. Show all posts

Thursday, August 8, 2019

[Laravel - Scheduler] การใช้ Environment Variable ของระบบปฏิบัติการใน Laravel Scheduler
[Laravel - Scheduler] How to Use Environment Variable of Operating System in Laravel Scheduler

Laravel scheduler ใช้ Crontab ในการรันคำสั่งต่างๆตามเวลาที่กำหนดบน Linux

เมื่อเราต้องการใช้งาน Laravel scheduler เราเพียงเพิ่มการตั้งค่าตามด้านล่างนี้ใน Cron ของ server
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
สำหรับการใช้ Environment Variable ของระบบปฏิบัติการ เราจำเป็นต้องสร้าง shell script ขึ้นมาตัวนึง เพื่อ export ตัวแปรที่เราต้องการใช้ก่อน

Monday, August 5, 2019

[Laravel - Model] ข้อควรระวังของการใช้ฟังก์ชั่น where และ orWhere ของ Laravel Model
[Laravel - Model] Warning: Using where and orWhere functions of Laravel Model

สมมติว่า
  • OrganizationChildren เป็น Laravel model ที่ผูกกับตาราง organization_children ในฐานข้อมูล
  • OrganizationChildren ประกอบด้วยฟิลด์ parent_organization_id และ child_organization_id 
  • $org1->id และ $org2->id เป็นค่า id ของ Organization โดยมีค่าเป็น 1 และ 2 ตามลำดับ

ถ้าเราต้องการ query ข้อมูล โดยใช้ SQL ดังนี้
select * 
from `organization_children` 
where (`parent_organization_id` = 1 and `child_organization_id` = 2) or 
(`parent_organization_id` = 2 and `child_organization_id` = 1)