尊龙凯时人生就是搏

laravel db ɾ³ý

laravel db ɾ³ý

LaravelÊÇÒ»¸öºÜÊÇÊܽӴýµÄPHP¿ò¼Ü£¬ÓÉÓÚÆä¼òÆÓÒ×ÓÃÇÒ¹¦Ð§Ç¿Ê¢£¬Ô½À´Ô½¶àµÄ¿ª·¢Õß×îÏÈʹÓÃËü¡£ÔÚLaravelÓ¦ÓóÌÐòÖУ¬Ê¹ÓÃÊý¾Ý¿âÊǷǾ­³£¼ûµÄ£¬¿ÉÊÇÔÚʹÓÃÖУ¬ÎÒÃÇ¿ÉÄÜ»áÓöµ½Êý¾Ýɾ³ýµÄÇéÐΡ£±¾ÎĽ«ÏÈÈÝLaravelÖÐÔõÑùɾ³ýÊý¾Ý¿âÖеÄÊý¾Ý¡£

LaravelÖеÄɾ³ý²Ù×÷¿ÉÒÔʹÓÃEloquent ORM»òÅÌÎʹ¹½¨Æ÷¡£ÎÒÃÇÏÈÏÈÈÝʹÓÃEloquent ORM¾ÙÐÐɾ³ýµÄÒªÁì¡£

ʹÓÃEloquent ORM¾ÙÐÐɾ³ý

ÔÚLaravelÖУ¬Eloquent ORMÊÇÒ»¸öºÜÊÇÇ¿Ê¢ºÍÒ×ÓÚʹÓõŤ¾ß¡£Ëü¿ÉÒÔ×ÊÖúÎÒÃǸüÇáËɵØÓëÊý¾Ý¿â½»»¥¡£ÎÒÃÇ¿ÉÒÔʹÓÃEloquent ORMɾ³ýÒ»¸ö»ò¶à¸öÊý¾Ý¿â¼Í¼¡£

1.1 µ¥¸ö¼Í¼ɾ³ý

ɾ³ýµ¥¸ö¼Í¼µÄ´úÂëºÜÊǼòÆÓ£¬Ö»ÐèʹÓÃdeleteÒªÁì¼´¿É¡£ÀýÈ磬ÎÒÃÇÓÐÒ»¸öUserÄ£×Ó£¬¸ÃÄ£×Ó¶ÔÓ¦ÁËÒ»¸öusers±í£º

// ɾ³ýidΪ1µÄÓû§
$user = AppUser::find(1);
$user->delete();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽫ɾ³ýusers±íÖÐidΪ1µÄ¼Í¼¡£

1.2 ¶à¸ö¼Í¼ɾ³ý

ÈôÊÇÎÒÃÇҪɾ³ý¶à¸ö¼Í¼£¬Ôò¿ÉÒÔʹÓÃwhereÌõ¼þ¾ÙÐÐɸѡ¡£ÀýÈ磬ÎÒÃÇҪɾ³ýËùÓÐÄêËê´óÓÚ30ËêµÄÓû§£¬¿ÉÒÔʹÓÃÈçÏ´úÂ룺

// ɾ³ýÄêËê´óÓÚ30ËêµÄÓû§
$users = AppUser::where('age', '>', 30)->get();
$users->delete();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽫ɾ³ýusers±íÖÐËùÓÐÄêËê´óÓÚ30ËêµÄ¼Í¼¡£

ʹÓÃÅÌÎʹ¹½¨Æ÷¾ÙÐÐɾ³ý

³ýÁËʹÓÃEloquent ORM¾ÙÐÐɾ³ýÖ®Í⣬ÎÒÃÇ»¹¿ÉÒÔʹÓÃÅÌÎʹ¹½¨Æ÷¾ÙÐÐɾ³ý¡£ÅÌÎʹ¹½¨Æ÷ÌṩÁ˸üÎÞаµÄ·½·¨À´¹¹½¨SQLÅÌÎÊÓï¾ä¡£

2.1 µ¥¸ö¼Í¼ɾ³ý

ÓëEloquent ORMÒ»Ñù£¬ÎÒÃÇ¿ÉÒÔʹÓÃÅÌÎʹ¹½¨Æ÷ɾ³ýµ¥¸ö¼Í¼¡£ÀýÈ磬ÎÒÃÇÓÐÒ»¸öusers±í£¬ÆäÖаüÀ¨Ò»¸öÃûΪidµÄ×ֶΡ£ÒªÉ¾³ýidΪ1µÄ¼Í¼£¬¿ÉÒÔʹÓÃÈçÏ´úÂ룺

// ɾ³ýidΪ1µÄÓû§
DB::table('users')->where('id', '=', 1)->delete();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽫ɾ³ýusers±íÖÐidΪ1µÄ¼Í¼¡£

2.2 ¶à¸ö¼Í¼ɾ³ý

ÈôÊÇÎÒÃÇҪɾ³ý¶à¸ö¼Í¼£¬Ôò¿ÉÒÔʹÓÃwhereInÌõ¼þ¾ÙÐÐɸѡ¡£ÀýÈ磬ÎÒÃÇҪɾ³ýidΪ1¡¢2¡¢3µÄÓû§£¬¿ÉÒÔʹÓÃÈçÏ´úÂ룺

// ɾ³ýidΪ1¡¢2¡¢3µÄÓû§
DB::table('users')->whereIn('id', [1, 2, 3])->delete();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂ뽫ɾ³ýusers±íÖÐidΪ1¡¢2¡¢3µÄ¼Í¼¡£

×ܽá

ÔÚLaravelÖУ¬É¾³ýÊý¾Ý¿â¼Í¼ºÜÊÇÈÝÒס£ÎÒÃÇ¿ÉÒÔʹÓÃEloquent ORM»òÅÌÎʹ¹½¨Æ÷¾ÙÐÐɾ³ý¡£ÔÚɾ³ý¼Í¼ʱ£¬ÇëÈ·±£ÄúÒѾ­È·ÈÑþ³ØýµÄ¹¤¾ßÊÇ׼ȷµÄ£¬²¢×ñÕÕ×î¼Ñʵ¼ùÒÔÈ·±£Ó¦ÓóÌÐòµÄÎȹÌÐÔ¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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