尊龙凯时人生就是搏

laravel ¶àÌõ¼þɾ³ý

laravel ÊÇÒ»¿î±ã½Ý¡¢ÓÅÑÅµÄ php web ¿ª·¢¿ò¼Ü £¬ËüΪ¿ª·¢ÕßÌṩÁ˸»ºñµÄ¹¦Ð§ºÍÒ×ÓÚʹÓõÄÓï·¨¡£ÔÚÏÖʵÏîÄ¿ÖÐ £¬¶àÌõ¼þɾ³ýÊÇÒ»¸ö¾­³£·ºÆðµÄÐèÇó¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓà laravel À´ÊµÏÖ¶àÌõ¼þɾ³ý¹¦Ð§¡£

Ò»¡¢ÐèÇóÆÊÎö

ÔÚÏÖʵ¿ª·¢ÖÐ £¬ÎÒÃǾ­³£ÐèҪƾ֤¶à¸öÌõ¼þÀ´É¾³ýÊý¾Ý¿âÖеļͼ¡£ºÃ±È £¬ÎÒÃÇÐèҪƾ֤Óû§ ID ºÍ²úÆ· ID ɾ³ýij¸öÓû§¹ºÖõÄij¸ö²úÆ·¼Í¼¡£ÔÚʹÓà Laravel ¾ÙÐпª·¢Ê± £¬¶àÌõ¼þɾ³ý¿ÉÒÔʹÓà Eloquent ÌṩµÄ where() ÒªÁìʵÏÖ¡£´úÂëÈçÏ£º

DB::table('table_name')
    ->where('column_name_1', '=', $value_1)
    ->where('column_name_2', '=', $value_2)
    ->delete();

µÇ¼ºó¸´ÖÆ

¿ÉÊÇ £¬ÈôÊÇÓжà¸öÌõ¼þÐèҪɾ³ý £¬ÄÇô´úÂë¾Í»á±äµÃÈß³¤¡£

¶þ¡¢½â¾ö¼Æ»®

ΪÏàʶ¾öÕâ¸öÎÊÌâ £¬ÎÒÃÇ¿ÉÒÔʹÓà Laravel ÌṩµÄÄ£×ÓÅÌÎÊÓï·¨À´ÊµÏÖ¶àÌõ¼þɾ³ý¡£ÕâÖÖÒªÁì¿ÉÒÔÔ½·¢¾«Á·¡¢Ò׶Á £¬²¢ÇÒ¿Éά»¤ÐÔ¸üºÃ¡£

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚÄ£×ÓÀàÖнç˵һ¸ö¸¨ÖúÒªÁì £¬¸ÃÒªÁì¿ÉÒÔÎüÊÕ¶à¸ö²ÎÊý £¬²¢½«ÕâЩ²ÎÊýת»¯ÎªÒ»¸öÅÌÎʽṹÆ÷¹¤¾ß£¨QueryBuilder£©¡£´úÂëÈçÏ£º

class ModelName extends Model
{
    // ½ç˵¸¨ÖúÒªÁì
    public function multiDelete(...$conditions)
    {
        // ½á¹¹ÅÌÎʽṹÆ÷¹¤¾ß
        $queryBuilder = $this->newQuery();

        // Ìí¼ÓÅÌÎÊÌõ¼þ
        foreach ($conditions as $condition) {
            list($column, $operator, $value) = $condition;
            $queryBuilder->where($column, $operator, $value);
        }

        // Ö´ÐÐɾ³ý²Ù×÷
        return $queryBuilder->delete();
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏ´úÂëÖÐ £¬ÎÒÃǽç˵ÁËÒ»¸ö multiDelete ¸¨ÖúÒªÁì £¬¸ÃÒªÁìÎüÊÕδ±ØÊýÄ¿µÄ²ÎÊý¡£Ã¿¸ö²ÎÊý¶¼ÊÇÒ»¸ö°üÀ¨Èý¸öÔªËصÄÊý×é £¬»®·Ö´ú±íÅÌÎÊÌõ¼þµÄÁÐÃû¡¢²Ù×÷·ûºÍÖµ¡£È»ºó £¬ÎÒÃÇʹÓÃÄ£× newQuery ÒªÁ콨ÉèÒ»¸öÅÌÎʽṹÆ÷¹¤¾ß £¬²¢Í¨¹ý foreach Ñ­»·½«´«ÈëµÄÿ¸öÌõ¼þÌí¼Óµ½ÅÌÎʽṹÆ÷¹¤¾ßÖС£×îºó £¬ÎÒÃÇŲÓÃÅÌÎʽṹÆ÷¹¤¾ßµÄ delete ÒªÁì £¬Ö´ÐÐɾ³ý²Ù×÷¡£

½ÓÏÂÀ´ £¬ÎÒÃÇ¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐʹÓÃÉÏÊöµÄÄ£×ÓÀàµÄ multiDelete ¸¨ÖúÒªÁìÀ´ÊµÏÖ¶àÌõ¼þɾ³ý¹¦Ð§¡£´úÂëÈçÏ£º

class ExampleController extends Controller
{
    public function delete(Request $request)
    {
        $userId = $request->input('user_id');
        $productId = $request->input('product_id');

        $result = ModelName::multiDelete(
            ['user_id', '=', $userId],
            ['product_id', '=', $productId]
        );

        if ($result) {
            return 'ɾ³ýÀÖ³É';
        } else {
            return 'ɾ³ýʧ°Ü';
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏ´úÂëÖÐ £¬ÎÒÃÇʹÓÃÄ£×ÓÀàµÄ multiDelete ¸¨ÖúÒªÁì £¬´«ÈëÁ½¸öÌõ¼þ £¬´ú±íҪɾ³ýÓû§ ID Ϊ $userId ÇÒ²úÆ· ID Ϊ $productId µÄ¼Í¼¡£×îºó £¬ÎÒÃǼì²éɾ³ý²Ù×÷µÄЧ¹û £¬²¢Æ¾Ö¤Ð§¹û·µ»Ø²î±ðµÄÐÅÏ¢¡£

Èý¡¢×ܽá

ÔÚ±¾ÎÄÖÐ £¬ÎÒÃÇÏÈÈÝÁËÔõÑùʹÓà Laravel ʵÏÖ¶àÌõ¼þɾ³ý¹¦Ð§¡£Í¨¹ýÌí¼ÓÒ»¸ö¸¨ÖúÒªÁì £¬ÎÒÃÇ¿ÉÒÔÔ½·¢ÓÅÑŵØÖÎÀí¶à¸öÅÌÎÊÌõ¼þ £¬²¢ÇÒÄܹ»Ô½·¢Àû±ãµØά»¤´úÂ롣ͬʱ £¬ÎÒÃÇҲѧϰÁËÔõÑùʹÓà Laravel µÄÄ£×ÓÅÌÎÊÓï·¨À´¹¹½¨ÅÌÎʽṹÆ÷¹¤¾ß £¬ÒÔ¼°ÔõÑùʹÓÃÅÌÎʽṹÆ÷¹¤¾ßÀ´Ö´ÐÐɾ³ý²Ù×÷¡£ÎÒÐÅÍÐ £¬ÕâЩ¼¼ÇÉÄܹ»×ÊÖúÄãÔÚÏÖʵÏîÄ¿ÖÐÔ½·¢¸ßЧµØ¾ÙÐпª·¢¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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