国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

Laravel中建Model

2020-03-22 20:13:58
字體:
供稿:網(wǎng)友
  • 以前使用的CI框架,最近學習使用Laravel框架了,把碰到的一些問題總結(jié)一下做個記錄,以便以后回顧,也希望可以幫到碰到同樣問題的朋友。

    在Laravel中數(shù)據(jù)庫表都是根據(jù)Laravel中寫好的程序去生成的,這樣的話便于使用git等版本控制進行管理整個項目。
    以建立User_address模型為例進行記錄:
    1、使用php artisan make:model User_address命令創(chuàng)建模型,如圖:
    創(chuàng)建模型成功
    2、成功之后再程序目錄app和database/migrations下會分別生成兩個文件,如圖:
    生成兩個文件

    3、打開database/migrations下生成的文件,這個文件就是控制生成數(shù)據(jù)庫表的文件,內(nèi)容如下:

    2015_06_02_071328_create_user_addresses_table.php中的代碼:<?phpuse Illuminate/Database/Schema/Blueprint;use Illuminate/Database/Migrations/Migration;html' target='_blank'>class CreateUserAddressesTable extends Migration {    /**     * Run the migrations.     *     * @return void     */    public function up()    {        Schema::create('user_addresses', function(Blueprint $table)        {                       $table->increments('address_id')                ->comment("主鍵");            $table->mediumInteger('user_id')                ->comment('用戶id');            $table->string('consignee', 60)                ->comment('收貨人');            $table->string('country', 60)                ->comment('國家');            $table->string('province', 60)                ->comment('省份');            $table->string('city', 60)                ->comment('市');            $table->string('district', 120)                ->comment('街道');            $table->string('address', 120)                ->comment('詳細地址');            $table->string('zip_code', 60)                ->comment('政編碼郵');            $table->string('tel', 60)                ->comment('固定電話');            $table->string('mobile', 60)                ->comment('手機');            $table->tinyInteger('is_default')                ->comment('是否是默認地址');        });    }    /**     * Reverse the migrations.     *     * @return void     */    public function down()    {        Schema::drop('addresses');    }}

    4、執(zhí)行:php artisan migrate 命令在數(shù)據(jù)庫中生成表User_address。
    這是生成表address的過程

    PHP編程

    鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

  • 發(fā)表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發(fā)表
    主站蜘蛛池模板: 桂阳县| 淳化县| 綦江县| 临朐县| 赤峰市| 黄陵县| 洱源县| 青浦区| 阆中市| 赤水市| 南投市| 岳西县| 德惠市| 庐江县| 临沧市| 庆阳市| 美姑县| 龙州县| 会昌县| 孙吴县| 霍州市| 鄱阳县| 元阳县| 杭锦后旗| 拉萨市| 枣阳市| 凤山市| 房山区| 荃湾区| 任丘市| 商河县| 万年县| 黄大仙区| 吉林市| 赫章县| 涟水县| 崇州市| 荔波县| 绵阳市| 会泽县| 荔波县|