[Day24]创建Table及捞取资料

创建migration迁移档案

首先先使用artisan指令: make:migration
创建一个产品table的迁移档案
php artisan make:migration create_products_table

更改迁移档案加入栏位

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateProductTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('code'); // 生成varcher(255)
            $table->string('name'); 
            $table->integer('price'); // int(11)
            $table->integer('quantity'); 
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down() // 可以使用rollback回到上一部
    {
        Schema::dropIfExists('products');
    }
}

接着在cmd输入:php migrate
会在MySQL生成以下Table
https://ithelp.ithome.com.tw/upload/images/20210922/20128999Z6TPaZkKJC.jpg

可以在资料库新增几笔资料
INSERT INTOtest.products(code,name,price,quantity) VALUES ('2', 'computer', '1000', '10');

那要怎麽从Laravel搜寻资量表资料呢?
在cmd输入: php artisan tinker
Tinker 可以允许您在命令行上与整个 Laravel 应用程序进行交互
接着在tinker中输入 DB::select('select * from products');
https://ithelp.ithome.com.tw/upload/images/20210922/201289991PAp0hDQfB.jpg
成功捞取到资料库资料罗


<<:  (Day25) Promise 语法糖 async/await

>>:  【Day11】:库函数包装—对於底层暂存器的操纵(下)

Day_30 RPI GPIO

openwrt虽然主力是在网路服务,但如果硬体与韧体的支援上有GPIO(通用型之输入输出的简称),也...

DAY06 探索性资料分析

一、当拿到资料後 1.问自己,想要这笔资料为你做什麽? 举例来说,今天你拿到一笔资料,老板要你去预测...

[所以我说 Google 你的测试] 品质到底是什麽?

嗨~ 我是 Robin : ) 这系列主要是我读关於这本书 Google 的软件测试之道 的一些读书...

[Day16]What is Merkle tree?

这篇会分成4个部分,分别是介绍merkle tree以及各种待会会用到的名词、实际看merkle ...

D-7. Rails API认证功能 && Find All Numbers Disappeared in an Array

今日会以昨日同份专案继续。 再次提醒,API Only,没有view。 为何需要验证。 总不可能让所...