zoukankan      html  css  js  c++  java
  • Laravel创建Model

    它已被用于CI框架。最近学习使用Laravel框架,要总结一些遇到的问题是一个创纪录,供以后调用。此外,我希望能够碰到同样的问题的朋友的帮助。

    在Laravel数据库表是根据Laravel写好的程序去生成的,这种话便于使用git等版本号控制进行管理整个项目。


    以建立User_address模型为例进行记录:
    1、使用php artisan make:model User_address命令创建模型。如图:
    创建模型成功
    2、成功之后再程序文件夹app和database/migrations下会分别生成两个文件。如图:
    生成两个文件

    3、打开database/migrations下生成的文件,这个文件就是控制生成数据库表的文件。内容例如以下:

    2015_06_02_071328_create_user_addresses_table.php中的代码:
    
    <?php
    
    use IlluminateDatabaseSchemaBlueprint;
    use IlluminateDatabaseMigrationsMigration;
    
    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、运行:php artisan migrate 命令在数据库中生成表User_address。
    这是生成表address的过程

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    【40讲系列1】数组、链表
    更改凭证类型
    将公司代码设置给生产性的(不能删除业务数据的配置)
    使用参考过账
    查看凭证行项目
    查看凭证过账行项目
    预制凭证
    做凭证时凭证日期等于过账日期
    英语-20210302
    自动计算税额
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4749061.html
Copyright © 2011-2022 走看看