×ðÁú¿­Ê±

thinkphpµÄɾ³ýÒªÁìÔõôʹÓÃ

Ò»¡¢Ê¹Óà delete ÒªÁì

ÔÚ ThinkPHP ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓà delete ÒªÁìÀ´É¾³ýÊý¾Ý£¬Õâ¸öÒªÁìºÜÊǼòÆÓ£¬Ö»ÐèÒªÔÚÄ£×ÓÖÐʹÓà delete ÒªÁì¼´¿É£¬ÀýÈ磺

$user = UserModel::get(1);
$user->delete();

µÇ¼ºó¸´ÖÆ

ÕâÑù¾Í¿ÉÒÔɾ³ý ID Ϊ 1 µÄÓû§ÁË¡£ÈôÄúµÄ Model δָ¶¨Ö÷¼ü£¬Ôò¿É½ÓÄÉÒÔÏ·½·¨£º

$user = UserModel::get(['name' => 'thinkphp']);
$user->delete();

µÇ¼ºó¸´ÖÆ

ÕâÑù¾Í¿ÉÒÔɾ³ýÃû³ÆΪ thinkphp µÄÓû§ÁË¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

¶þ¡¢Á´Ê½É¾³ý

ÔÚ ThinkPHP ÖУ¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃÁ´Ê½É¾³ýÀ´É¾³ýÊý¾Ý£¬Õâ¸öÒªÁì½ÏÁ¿³£Ó㬺ñȣº

$user = UserModel::where('id', 1)->delete();

µÇ¼ºó¸´ÖÆ

Õâ¸öÒªÌå»áɾ³ý ID Ϊ 1 µÄÓû§Êý¾Ý£¬²¢·µ»Øɾ³ýµÄÐÐÊý¡£

Èý¡¢Èíɾ³ý

ÔÚ ThinkPHP ÖУ¬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÈíɾ³ýÀ´É¾³ýÊý¾Ý¡£ËùνÈíɾ³ý£¬¾ÍÊÇ°ÑÊý¾Ý±ê¼ÇΪÒÑɾ³ý£¬¶ø²»ÊÇÕæÕýµÄɾ³ýÊý¾Ý¡£Õâ¸ö²Ù×÷ÔÚÊý¾Ý»Ö¸´¡¢Êý¾ÝÅÌÎʵȷ½ÃæºÜÓÐÓá£ÎÒÃÇ¿ÉÒÔÔÚÄ£×ÓÖÐʹÓÃÈíɾ³ý£¬ÀýÈ磺

class UserModel extends Model
{
    use SoftDelete;

    protected $deleteTime = 'delete_time';

    protected $defaultSoftDelete = 0;

    protected $autoWriteTimestamp = true;
}

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃÇʹÓÃÁË SoftDelete µÄ Trait£¬ÉèÖÃÁË delete_time ×Ö¶ÎΪɾ³ýʱ¼ä¡£ÕâÑù£¬ÎÒÃÇÔÚʹÓà delete ÒªÁì»òÁ´Ê½É¾³ýÒªÁìʱ£¬¶¼»á½«ÏìÓ¦µÄÊý¾Ý±ê¼ÇΪÒÑɾ³ý£¬¶ø²»ÊÇÕæÕýµÄɾ³ýÊý¾Ý¡£

ËÄ¡¢ÅúÁ¿É¾³ý

ÔÚ¿ª·¢ÏîĿʱ£¬ÎÒÃÇÓÐʱÐèÒªÅúÁ¿É¾³ýÊý¾Ý£¬ÓÐÒÔÏÂÁ½ÖÖÒªÁ죺

1.ʹÓà SQL Óï¾ä

ÎÒÃÇ¿ÉÒÔÖ±½ÓʹÓà SQL Óï¾äÀ´ÅúÁ¿É¾³ýÊý¾Ý£¬ÀýÈ磺

Db::table('user')->where('id', 'in', [1, 2, 3])->delete();

µÇ¼ºó¸´ÖÆ

Õâ¸öÒªÌå»áɾ³ý ID Ϊ 1¡¢2¡¢3 µÄÓû§Êý¾Ý£¬²¢·µ»Øɾ³ýµÄÐÐÊý¡£

2.ʹÓÃÄ£× delete ÒªÁì

ÎÒÃÇÒ²¿ÉÒÔʹÓÃÄ£× delete ÒªÁìÀ´ÅúÁ¿É¾³ýÊý¾Ý£¬ÀýÈ磺

UserModel::destroy([1, 2, 3]);

µÇ¼ºó¸´ÖÆ

Õâ¸öÒªÌå»áɾ³ý ID Ϊ 1¡¢2¡¢3 µÄÓû§Êý¾Ý£¬²¢·µ»Øɾ³ýµÄÐÐÊý¡£

ÒÔÉϾÍÊÇthinkphpµÄɾ³ýÒªÁìÔõôʹÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

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