ข้ามไปที่เนื้อหาหลัก

บทความ

กำลังแสดงโพสต์จาก พฤศจิกายน, 2023

แก้ไขปัญหา Laravel+Vite redirect ไปที่ path build

  ก่อนหน้านี้ติดปัญหาเรื่องการพัฒนาเว็บแอพลิเคชันด้วย Laravel และ Vuejs โดยใช้ Vite ควบคู่ในการพัฒนา Frontend ตอนรัน npm run dev ก็ดูเหมือนจะใช้งานได้ปกติ แต่พอมาลอง build ดูปรากฏว่าตัว application คอย redirect ไปที่ path /build ตลอดเลย พอหาข้อมูล ไปๆ มาๆ ก็เจอว่าตอนที่เขียนเราใช้ router ของฝั่ง vuejs ซึ่งทำเป็น SPA const router = createRouter({     history: createWebHistory(import.meta.env.BASE_URL), }); จากโค๊ดด้านบนนี่แหละที่ มึนอยู่หลาย ชั่วโมง แก้ง่ายๆ ที่สุด คือทำแบบนี้ const router = createRouter({     history: createWebHistory(), }); เข้าใจว่า import.meta.env.BASE_URL ค่า default น่าจะเป็น /build ถ้าเอาออกจะช่วยแก้ไขปัญหาได้ แต่ยังไม่ได้ลองว่าถ้าเราไปกำหนด env ตัวนี้ขึ้นมาก็อาจจะช่วยแก้ไขปัญหาได้ด้วยหรือเปล่า? VITE_BASE_URL="/" ใครลองแล้วได้ผลมาคอมเม้นกันด้วยนะ วันนี้ไปก่อนละ

การอัปโหลดไฟล์ใน PHP: ขั้นตอนและตัวอย่างโค้ด

การอัปโหลดไฟล์เป็นหนึ่งในฟีเจอร์ที่สำคัญในการพัฒนาเว็บแอปพลิเคชัน ในบทความนี้เราจะสอนคุณวิธีทำการอัปโหลดไฟล์ใน PHP ด้วยขั้นตอนที่ง่ายต่อการติดตาม ตัวอย่างนี้จะชี้แนะเกี่ยวกับการใช้ฟอร์ม HTML และโค้ด PHP เพื่อรับและจัดการกับไฟล์ที่ผู้ใช้ส่งมา ขั้นตอนที่ 1: สร้างฟอร์ม HTML <!DOCTYPE html> <html lang="th"> <head>   <meta charset="UTF-8">   <meta name="viewport" content="width=device-width, initial-scale=1.0">   <title>แบบฟอร์มอัปโหลดไฟล์</title> </head> <body>   <h2>แบบฟอร์มอัปโหลดไฟล์</h2>   <form action="upload.php" method="post" enctype="multipart/form-data">     <label for="file">เลือกไฟล์:</label>     <input type="file" name="file" id="file" required>     <br>     <button type="submit">อัปโหลด</button>   </form> </body> </html> ขั้นตอนที่ 2:

เรื่องสยองของ Bug ใน PHP 7.4.18

เมื่อจู่ๆ วันหนึ่ง คุณก็ไม่สามารถที่จะ insert ข้อมูลใหม่ได้เพราะเจอ error ฟ้องกลับมาว่า . operator does not exist: boolean = integer หรือ SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column “column_boolean” is of type boolean but the expression is of type integer เรื่องสยองหลายบรรทัดมันเกิดขึ้นในตอนที่ผม deploy PHP application ขึ้นไปยัง staging environment error ต่างๆ ก็ไหลมารวมกัน เนื่องจากใน code นั้นประกอบไปด้วย eloquent ที่เกี่ยวข้องกับ boolean เช่น $this->model->where('is_active', true)->first(); หรือจะเป็นเรื่องของการ insert/update // Insert $this->model->update([ 'email' => 'thanos@rabbit.co.th', 'is_active' => true ]); // Update $this->model->update(['is_active' => true]); ซึ่งสาวก Laravel หรือ Lumen ที่กำลังใช้ Postgres น่าจะเจอกันอยู่นะ 5555+ Error รัวๆ แบบไม่เกรงใจพื้นที่ Log 5555+ แล้วทำไมถึงเกิดปัญหานี้ขึ้น? ทำไม production หรือ local ไม่เจอปัญหานี้ล่ะ? ตอนแรกก็แอบสงสัย  Eloquent  ว่าได้มีแอบการแ

Introduction to PHP: Powering the Web with Dynamic Content

 PHP, which stands for Hypertext Preprocessor, is a server-side scripting language that has been a cornerstone in web development for decades. Originally designed for creating dynamic web pages, PHP has evolved into a versatile language used by developers worldwide to build robust, scalable, and feature-rich web applications. A Brief History: PHP was created in 1994 by Rasmus Lerdorf and initially stood for "Personal Home Page." Over the years, it has gone through significant improvements and iterations, transforming into the recursive acronym we know today. Server-Side Scripting: PHP operates on the server side of web development. Unlike client-side languages such as JavaScript, which execute in the user's browser, PHP code is executed on the server before the HTML is sent to the client. This server-side nature enables PHP to perform tasks such as interacting with databases, handling user authentication, and generating dynamic content based on user input. Why PHP? Ease o

ทำความเข้าใจเกี่ยวกับ Laravel Eloquent

  สำหรับมือใหม่ที่เริ่มพัฒนาเว็บแอพพลิเคชันโดยใช้ Laravel เมื่อต้องทำงานที่เกี่ยวข้องกับ database อาจจะต้องปวดหัวกับ Eloquent และเรื่องราวในวันนี้จะมาพูดถึงว่า มันคืออะไร และใช้งานยังไง อย่างที่ใน docs ได้อธิบายคร่าวๆ ว่า Eloquent คือ ORM ตัวหนึงที่เสริมในเรื่องของ Relations เข้ามา ซึ่งการเชื่อมโยง หรือ Relations ไม่ไช่การ join แต่เป็นการบอกให้ Model รู้ว่ามี relations กับ table ไหนใน database ของเรา ยกตัวอย่างเช่น ข้อมูลของตาราง Users ที่เราออกแบบว่าจะแยกข้อมูลกันดังนี้ Users Addresses จาก 2 ตารางด้านบน เราจะทำการเขียนโค้ดให้เชื่อมข้อมูลกันจาก Model ของ Users โดยจะต้องมี column ที่นำมาเชื่อมกันด้วย เช่น ที่ตารางของ addresses จะต้องมี column user_id เก็บไว้ด้วย โดยเราจะใช้ Relation One To One ในการทำ relation กัน  หลายๆ คนจะ งง ว่ามำดึงข้อมูลมายังไง จริงๆ ตัว Eloquent จะทำการ query มาใหม่ไม่ได้ใช้ query เดียว จาก ตัวอย่างข้างบน ถ้าทำถูกต้องได้ 2 query select * from users where id='1' select * from addresses where user_id=1