尊龙凯时人生就是博

laravelÔõô×÷·Ïcreated_at

ÔÚlaravel¿ò¼ÜÖÐ £¬Ã¿¸öeloquentÄ£×Ó¶¼Ä¬ÈÏ°üÀ¨ÁËcreated_atºÍupdated_atÁ½¸öʱ¼ä´Á×ֶΡ£ÕâÁ½¸ö×ֶμͼÁËÄ£×ӵĽ¨ÉèºÍ¸üÐÂʱ¼ä¡£ÕâÑù×öµÄÀûÒæÊÇÀû±ã¼Í¼Êý¾ÝµÄ¸üÐÂʱ¼ä £¬ÒÔ¼°Àû±ãʵÏÖһЩ¹¦Ð§ £¬ºÃ±Èƾ֤½¨Éèʱ¼äºÍ¸üÐÂʱ¼äÅÅÐòµÈµÈ¡£

È»¶ø £¬ÔÚijЩ³¡¾°Ï £¬ÎÒÃÇ¿ÉÄܲ»ÐèÒªÕâÁ½¸öʱ¼ä´Á×ֶΡ£ºÃ±ÈÓÐЩÀϵÄÊý¾Ý¿â±í¿ÉÄÜûÓÐÕâÁ½¸ö×ֶΠ£¬»òÕßÎÒÃÇ»ù´¡²»ÐèÒª¼Í¼Êý¾ÝµÄ½¨ÉèºÍ¸üÐÂʱ¼ä¡£ÔÚÕâÖÖÇéÐÎÏ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚÄ£×ÓÖмÓÈëÏÂÃæÕâÁ½ÐдúÂëÀ´×÷·Ï created_at ºÍ updated_at£º

public $timestamps = false;

µÇ¼ºó¸´ÖÆ

ÕâÑù×ö¿ÉÒÔÔÚÄ£×ÓÖÐ×÷·Ï created_at ºÍ updated_at ×ֶΡ£¿ÉÊÇҪעÖصÄÊÇ £¬×÷·ÏÕâÁ½¸öʱ¼ä´Á×ֶλᵼÖÂһЩLaravelÄÚÖõĹ¦Ð§Ê§Ð§¡£ºÃ±ÈÄ£×ÓÎÞ·¨Í¨¹ý created_at ºÍ updated_at ×ֶξÙÐÐÅÅÐò £¬Ò²ÎÞ·¨×Ô¶¯¼Í¼Êý¾ÝµÄ½¨ÉèºÍ¸üÐÂʱ¼ä¡£

ÈôÊÇÎÒÃÇÖ»ÐèÒª×÷·ÏÆäÖÐÒ»¸öʱ¼ä´Á×ֶΠ£¬ºÃ±ÈÖ»×÷·Ï created_at £¬ÄÇô¿ÉÒÔÕâÑù×ö£º

// Ö»×÷·Ï created_at
const UPDATED_AT = 'updated_at';

µÇ¼ºó¸´ÖÆ

Õâ¸öÒªÁìÊǽ« UPDATED_AT ³£Á¿¸³ÖµÎª updated_at ×Ö·û´® £¬¶øĬÈÏÇéÐÎÏ UPDATED_AT µÄÖµÊÇ updated_at £¬Òò´ËÕâÑù×öÖ»×÷·ÏÁË created_at¡£

µ±ÎÒÃÇ×÷·ÏÁËÕâЩʱ¼ä´Á×Ö¶Îºó £¬ÈôÊÇÎÒÃÇÐèҪʵÏÖ×Ô¼ºµÄÊý¾Ý½¨Éèʱ¼äºÍ¸üÐÂʱ¼äµÄ¼Í¼ £¬ÄÇôÎÒÃǾÍÐèÒªÊÖ¶¯±àд´úÂëÀ´ÊµÏÖ¡£ÏÂÃæÊÇÒ»¸öÀý×Ó£º

// ÔÚÄ£×ÓÖÐʵÏÖ×Ô½ç˵ʱ¼ä´Á×Ö¶Î
protected $dateFormat = 'U';
protected static function boot()
{
    parent::boot();
    static::creating(function ($model) {
        $model->create_time = $model->freshTimestamp();
    });
    static::updating(function ($model) {
        $model->update_time = $model->freshTimestamp();
    });
}

µÇ¼ºó¸´ÖÆ

Õâ¸öÀý×ÓÖÐ £¬ÎÒÃÇÔÚÄ£×ÓÖнç˵ÁË create_time ºÍ update_time Á½¸ö×Ö¶ÎÀ´¼Í¼Êý¾ÝµÄ½¨Éèʱ¼äºÍ¸üÐÂʱ¼ä¡£Í¬Ê± £¬ÎÒÃÇͨ¹ý½ç˵ $dateFormat ÊôÐÔÀ´ÐÞ¸ÄĬÈϵÄʱ¼äÃûÌá£ÔÚ boot ÒªÁìÖÐ £¬ÎÒÃÇͨ¹ý creating ºÍ updating ÊÂÎñÀ´Îª create_time ºÍ update_time ¸³Öµ¡£freshTimestamp ÒªÁì¿ÉÒÔ»ñÈ¡×îеÄʱ¼ä´Á¡£

×ܽáһϠ£¬×÷·Ï created_at ºÍ updated_at ¿ÉÒÔͨ¹ýÔÚÄ£×ÓÖÐÌí¼Ó $timestamps = false »òÐÞ¸Ä UPDATED_AT ³£Á¿À´ÊµÏÖ¡£×÷·ÏÕâЩʱ¼ä´Á×ֶλáÓ°ÏìLaravelÖÐһЩÄÚÖõĹ¦Ð§ £¬ºÃ±ÈÅÅÐòºÍ×Ô¶¯¼Í¼ʱ¼äµÈµÈ¡£ÈôÊÇÐèÒª×Ô¼ºÊµÏÖʱ¼ä´ÁµÄ¼Í¼ £¬¿ÉÒÔͨ¹ýÊÖ¶¯±àд´úÂëÀ´ÊµÏÖ¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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