尊龙凯时人生就是博

laravelÊý¾Ý±íÔõôÉèÖÃ

laravelÊÇÏÖ´úphp¿ª·¢ÖÐ×îÊ¢ÐеĿò¼ÜÖ®Ò»¡£ËüÌṩÁËÐí¶àÓÐÓõĹ¦Ð§ºÍ¹¤¾ß £¬ÆäÖÐ×îÖ÷ÒªµÄÊÇËüµÄorm¡£¿ÉÒÔʹÓÃorm£¨¹¤¾ß¹ØϵӳÉ䣩ÇáËɵزÙ×÷Êý¾Ý¿â¡£ÔÚlaravelÖÐ £¬Ê¹ÓÃorm½¨ÉèÊý¾Ý±í²¢ÇÒÉèÖÃÊý¾Ý±íµÄÒªÁìºÜÊǼòÆÓ¡£ÔÚ±¾ÎÄÖÐ £¬ÎÒÃǽ«ÌÖÂÛÔõÑùʹÓÃlaravelÀ´ÉèÖÃÊý¾Ý±í¡£

LaravelÊý¾Ý¿âǨáã

ÔÚLaravelÖÐ £¬Êý¾Ý±íµÄÉèÖÃÊÇͨ¹ýÊý¾Ý¿âǨá㣨database migration£©À´Íê³ÉµÄ¡£Êý¾Ý¿âǨáãÊÇÒ»ÖÖ°æ±¾¿ØÖÆ £¬ÓÃÓÚÖÎÀíÊý¾Ý±íµÄ½á¹¹×ª±ä¡£Ã¿Ò»¸öǨá㶼ÐÎòÁËÊý¾Ý¿âģʽµÄת±ä¡£Ã¿¸ö°æ±¾¿ØÖÆǨá㶼·ºÆðÁËÒ»´ÎÊý¾Ý¿âÉý¼¶ £¬ÒÔÊÇÄã¿ÉÒԻص½Ö®Ç°µÄ°æ±¾»òÕßÉý¼¶µ½½Ïеİ汾¡£¸üÖ÷ÒªµÄÊÇ £¬LaravelÌṩÁ˱ã½ÝµÄÏÂÁîÐй¦Ð§À´½¨ÉèºÍÖÎÀíǨáã¡£ÕâÑùÄã¾Í¿ÉÒÔºÜÈÝÒ×µØÏòÊý¾Ý¿âÌí¼Ó»òɾ³ý±í¸ñ¡£Òò´Ë £¬ÔÚÕâ¸öÀú³ÌÖÐ £¬Äã²»±ØÊÖ¶¯±àдSQL´úÂë¡£

LaravelǨáãµÄ½¨Éè

Ê×ÏÈ £¬ÔÚLaravelÖн¨ÉèǨáãºÜÊǼòÆÓ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸öÐÂǨá㣺

php artisan make:migration create_users_table

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁ½¨ÉèÒ»¸öеÄǨáã £¬ÃûΪ¡°create_users_table¡±¡£Ç¨á㽫ÉúÑÄÔÚ¡°database/migrations¡±Ä¿Â¼Ï¡£Õâ¸öĿ¼¾ÍÊÇLaravel¿ò¼Ü×Ô´øµÄÊý¾Ý¿âǨáãĿ¼¡£

·­¿ª¸Õ½¨ÉèµÄǨáã¡£Ä㽫¿´µ½Ò»¸ö¿ÕµÄ¡°up¡±ÒªÁì £¬ÕâÊǵ±ÄãǨáãʱִÐеĴúÂë¡£ÏÂÃæÊÇÕâ¸öÒªÁìµÄ¼òÆӵĽṹ£º

public function up()
{
    //
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÒªÁìÖÐ £¬Äã¿ÉÒÔ±àдÓÃÓÚ½¨ÉèÊý¾Ý±íµÄ´úÂë¡£ÎÒÃǽ«ÔÚÏÂÃæµÄʾÀýÖÐÚ¹ÊÍ¡£

LaravelÊý¾ÝÀàÐÍ

ÔÚLaravelÖÐ £¬ÓжàÖÖÊý¾ÝÀàÐͿɹ©Ñ¡Ôñ £¬ÓÃÓÚÐÎòÊý¾Ý±íÁеÄÀàÐÍ¡£ÔÚÏÂÃæµÄʾÀýÖÐ £¬ÎÒÃǽ«ÏÈÈÝһЩ¿ÉÓõÄÊý¾ÝÀàÐÍ¡£

1.×ÔÔöID

$table->bigIncrements(‘id’)

2.ÕûÊý

$table->integer(‘age’)

3.³¤ÕûÊý

$table->bigInteger(‘views’)

4.СÊý

$table->decimal(‘price’, 5, 2)

5.×Ö·û´®

$table->string(‘name’)

6.³¤Îı¾

$table->longText(‘description’)

7.ÈÕÆÚ

$table->date(‘dob’)

8.ÈÕÆÚʱ¼ä

$table->dateTime(‘published_at’)

9.²¼¶û

$table->boolean(‘is_active’)

10.JSON

$table->json(‘options’)

11.ʱ¼ä´Á

$table->timestamps()

LaravelÊý¾Ý±íµÄÉèÖÃ

ʹÓÃÉÏÃæµÄÏÂÁÉèǨáã²¢·­¿ª¡°up¡±ÒªÁì¡£½ÓÏÂÀ´ £¬ÄãÐèÒªÉèÖÃÊý¾Ý±íµÄÃû³Æ¡¢ÁÐÒÔ¼°ËüÃǵÄÀàÐͺÍÆäËûϸ½Ú¡£ÏÂÃæÊÇÔõÑùÉèÖÃÒ»¸öÃûΪ¡°users¡±µÄÊý¾Ý±í£º

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÊö´úÂëÖÐ £¬ÎÒÃÇͨ¹ýŲÓá°Schema::create¡±ÒªÁìÀ´½¨ÉèÊý¾Ý±í¡£ÔÚŲÓá°Schema::create¡±ÒªÁìʱ £¬ÎÒÃÇÐèҪת´ïÊý¾Ý±íÃû³ÆºÍÒ»¸ö»Øµ÷ÒªÁì £¬Õâ¸ö»Øµ÷ÒªÁìÓÃÓÚÐÎòÕâ¸öÊý¾Ý±íµÄÁкÍÆäËûϸ½Ú¡£Ôڻص÷ÒªÁìÖÐ £¬Ê¹Óá°Blueprint¡±ÀཨÉèÁС£Èç £¬ÎÒÃǽ¨ÉèÁËÒ»¸öÃû³ÆΪ¡°id¡±µÄ×ÔÔöÁÐ £¬²¢ÇÒÕâ¸öÁÐÊÇ´ËÊý¾Ý±íµÄÖ÷¼ü¡£ÁеÄÃû³ÆʹÓÃ×Ö·û´®À´ÌåÏÖ £¬ÁеÄÀàÐÍ¿ÉÒÔʹÓÃÉÏÃæÁгöµÄÈκÎÊý¾ÝÀàÐÍ¡£

ŲÓá°Schema::create¡±ÒªÁ콫ÔÚÊý¾Ý¿âÖн¨ÉèÒ»¸öÃûΪ¡°users¡±µÄ±í¡£ÈôÊÇÊý¾Ý±íÒѾ­±£´æ £¬ÄãÈÔÈ»¿ÉÒÔʹÓÃÕâ¸öÏÂÁîÀ´ÏòËüÌí¼Ó¸ü¶àµÄÁлò¸ü¸ÄËüµÄ½á¹¹¡£ÎªÁËÍê³ÉÕâ¸öʹÃü £¬ÄãÐèҪʹÓá°Schema::table¡±ÒªÁì £¬²¢Ôڻص÷º¯ÊýÖÐÖ¸¶¨¸ü¸Ä¡£

ÀýÈç £¬ÏÂÃæµÄ´úÂ뽫ÏòÃûΪ¡°users¡±µÄÊý¾Ý±íÌí¼ÓÒ»¸öÃûΪ¡°phone¡±µÄÁУº

public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('phone')->after('email');
    });
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖÐ £¬ÎÒÃÇͨ¹ýŲÓá°Schema::table¡±ÒªÁìÀ´¸ü¸üÃûΪ¡°users¡±µÄÊý¾Ý±í¡£¸ü¸ÄµÄÏêÇéÊÇÈÃǨá㽨ÉèÒ»¸öÃûΪ¡°phone¡±µÄÁÐ £¬²¢ÇÒ½«Æä°²ÅÅÔÚ¡°email¡±ÁÐÖ®ºó¡£

LaravelǨáãµÄÔËÐÐ

ÏÖÔÚ £¬ÎÒÃÇÒѾ­½¨ÉèÁËÒ»¸ö¼òÆÓµÄÊý¾Ý±í¡£½ÓÏÂÀ´ £¬ÎÒÃÇÐèÒªÔËÐÐǨáã²¢½«¸ü¸ÄÉúÑĵ½Êý¾Ý¿âÖС£ÒªÔËÐÐǨáã £¬ÇëʹÓÃÒÔÏÂÏÂÁ

php artisan migrate

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁÔËÐÐËùÓÐÉÐδÔËÐеÄǨáã¡£

LaravelǨáãµÄ»Ø¹ö

LaravelÌṩÁËÒ»¸öÀû±ãµÄÎÊÌâ»Ø¹öÏÂÁî £¬ËüÓÃÓÚ³·»Ø֮ǰÔËÐеÄǨáã¡£ÔÚ³·»ØǨáãʱ £¬Laravel»á×Ô¶¯»Ö¸´¸ü¸ÄÇ°°æ±¾µÄÊý¾Ý±í½á¹¹¡£Òª»Ø¹öÒ»¸öǨáã £¬ÇëʹÓÃÒÔÏÂÏÂÁ

php artisan migrate:rollback

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁ»Ø¹ö×îºóÒ»¸öǨáã¡£ÈôÊÇÄãÏë³·»Ø¸ü¶àµÄǨáã £¬ÇëʹÓá°–step¡±²ÎÊýºÍÊý×ÖÀ´Ö¸¶¨Òª»Ø¹öµÄǨáãÊýÄ¿¡£ÀýÈ磺

php artisan migrate:rollback --step=2

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁ»Ø¹ö×îºóÁ½¸öǨáã¡£

×ܽá

LaravelÌṩÁËÒ»ÖÖÇáÓ¯ÒªÁìÀ´ÖÎÀíÊý¾Ý¿â½á¹¹×ª±ä¡£Ê¹ÓÃÊý¾Ý¿âǨáã £¬¿ÉÒÔÇáËɵØÏòLaravelÓ¦ÓóÌÐòÌí¼Ó»òɾ³ýÊý¾Ý±í £¬ÕâÊÇΪ¼á³ÖÓÅÒìµÄ°æ±¾¿ØÖƶø±ØÐèµÄ¡£ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÌÖÂÛÁËÔÚLaravelÖÐÔõÑù½¨ÉèºÍÉèÖÃÊý¾Ý±í £¬ÒÔ¼°ÔõÑùÔËÐкͻعöǨáã¡£ÈôÊÇÄã×ñÕÕÕâЩ°ì·¨ £¬Ä㽫Äܹ»ÔÚLaravelÖÐÇáËɵؽ¨ÉèºÍÖÎÀíÊý¾Ý±í¡£

ÒÔÉϾÍÊÇlaravelÊý¾Ý±íÔõôÉèÖõÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ