尊龙凯时人生就是博

laravelɾ³ý¶àÌø

laravelÊÇÒ»¿îºÜÊÇÊܽӴýµÄphp¿ò¼Ü£¬ËüÌṩÁËһϵÁÐÇ¿Ê¢µÄ¹¦Ð§À´×ÊÖú¿ª·¢ÕßÔ½·¢¸ßЧµØ¹¹½¨Ó¦ÓóÌÐò¡£ÔÚlaravelÖУ¬É¾³ýÒ»Ìõ¼Í¼ÊǺÜÊǼòÆӵġ£¿ÉÊÇ£¬ÈôÊÇÎÒÃÇÐèҪɾ³ý¶àÌõ¼Í¼ÄØ£¿±¾ÆªÎÄÕ¾ͻáÏÈÈÝlaravelÔõÑùɾ³ý¶àÌõ¼Í¼¡£

ÔÚLaravelÖУ¬EloquentÌṩÁËÐí¶àÒªÁìÀ´É¾³ý¼Í¼¡£ÆäÖУ¬×î³£ÓõÄÒªÁì¿ÉÄܾÍÊÇdeleteÒªÁì¡£ÀýÈ磺

$user = User::find(1);
$user->delete();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂ뽫ɾ³ýidΪ1µÄÓû§¼Í¼¡£¿ÉÊÇ£¬ÈôÊÇÎÒÃÇÐèҪɾ³ý¶àÌõ¼Í¼ÄØ£¿ÕâʱÎÒÃÇ¿ÉÒÔʹÓÃwhereInÒªÁì¡£ÀýÈ磺

$ids = [1, 2, 3];
User::whereIn('id', $ids)->delete();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂ뽫ɾ³ýidΪ1¡¢2¡¢3µÄÈýÌõ¼Í¼¡£

¿ÉÊÇ£¬whereInÒªÁìÖ»ÊÊÓÃÓÚɾ³ýÖ¸¶¨µÄ¼Í¼¡£ÈôÊÇÎÒÃÇÐèҪƾ֤Ìõ¼þɾ³ý¼Í¼ÄØ£¿ÕâʱÎÒÃÇ¿ÉÒÔʹÓÃwhereÒªÁì¡£ÀýÈ磺

User::where('age', '>', 18)->delete();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂ뽫ɾ³ýÄêËê´óÓÚ18ËêµÄËùÓÐÓû§¼Í¼¡£

³ýÁËÉÏÊöÒªÁìÍ⣬Laravel»¹ÌṩÁËÆäËûһЩҪÁìÀ´É¾³ý¶àÌõ¼Í¼£º

delete()£ºÉ¾³ýËùÓмͼ¡£

truncate()£ºÇå¿Õ±íÖеÄËùÓмͼ¡£

¿ÉÊÇ£¬ÕâÁ½¸öÒªÁ춼ÊDz»¿ÉÄæµÄ£¬Ö´Ðкó½«ÎÞ·¨»Ö¸´Êý¾Ý¡£Òò´ËÔÚʹÓÃʱһ¶¨ÒªÉóÉ÷¡£

³ý´ËÖ®Í⣬Laravel»¹ÌṩÁËÒ»¸öºÜÊÇÓÐÓõÄÒªÁìforceDelete()£¬Õâ¸öÒªÁì¿ÉÒÔÓÀÊÀɾ³ý¼Í¼£¬×ÝÈ»ÊÇʹÓÃÁËSoftDeletesÒ²»á±»É¾³ý¡£ÀýÈ磺

$users = User::onlyTrashed()->where('deleted_at', '<', now()->subMonths(6))->get();
$users->forceDelete();

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂ뽫ɾ³ýÒѾ­±»Èíɾ³ý6¸öÔµÄÓû§¼Í¼¡£

×ܽáһϣ¬ÔÚLaravelÖÐɾ³ý¶àÌõ¼Í¼ÓÐÒÔϼ¸ÖÖÒªÁ죺

delete()£ºÉ¾³ýÖ¸¶¨µÄ¼Í¼¡£

whereIn()£ºÉ¾³ýÖ¸¶¨µÄÒ»×é¼Í¼¡£

where()£ºÆ¾Ö¤Ìõ¼þɾ³ý¼Í¼¡£

truncate()£ºÇå¿Õ±íÖеÄËùÓмͼ¡£

forceDelete()£ºÓÀÊÀɾ³ý¼Í¼¡£

ÐèҪעÖصÄÊÇ£¬ÔÚɾ³ý¶àÌõ¼Í¼ʱһ¶¨ÒªÉóÉ÷£¬È·ÈÏÎÞÎóºóÔÙÖ´ÐÐɾ³ý²Ù×÷¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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