วันอังคารที่ 4 สิงหาคม พ.ศ. 2558

วิธีทำให้ Laravel ติดต่อกับ MySql

วิธีทำให้ Laravel ติดต่อกับ MySql

1.สร้างฐานข้อมูล(Database)
2.คอนฟิกในการเชื่อมฐานข้อมูล จะถูกกำหนดอยู่ในไฟล์ app/config/database.php
3.รัน migrate เพื่อแก้ไขโครงสร้างฐานข้อมูล ด้วยคำสั่ง  php artisan migrate:make users เพื่อสร้างไฟล์ class ขึ้นมาไว้ในไดเร็กทอรี app/database/migrations/[current date]_users.php
4.แก้ไขไฟล์ app/database/migrations/[current date]_users.php
public function up()
{
Schema::create('users', function($table)
            {
                $table->increments('id');
                $table->string('first_name', 128);
                $table->string('last_name', 128);
                $table->string('email', 128);
  $table->timestamps();
            });
}
public function down()
{
Schema::drop('users');

}
5.รัน php artisan migrate อีกครั้งเพื่อสร้าง table users

ที่มา
http://spalinux.com/2015/01/laravel-connect-to-database
http://www.taroworldtaro.com/laravel-2-migrates-seeders/
http://ethaizone.com/blog/2012/10/%E0%B9%80%E0%B8%A3%E0%B8%B4%E0%B9%88%E0%B8%A1%E0%B8%95%E0%B9%89%E0%B8%99%E0%B8%81%E0%B8%B1%E0%B8%9A-laravel-migrations/

ไม่มีความคิดเห็น:

แสดงความคิดเห็น