尊龙凯时人生就是搏

laravelÅÌÎÊÌض¨×Ö¶Î

ÔÚ¾ÙÐÐlaravelÊý¾Ý¿âÅÌÎÊʱ£¬ÎÒÃÇͨ³£ÐèÒªÖ¸¶¨Òª¼ìË÷µÄÌض¨×ֶΡ£laravelÌṩÁ˼¸ÖÖ²î±ðµÄÒªÁìÀ´ÊµÏÖÕâ¸öÄ¿µÄ¡£ÒÔÏÂÊÇÕâЩҪÁìµÄÏêϸÏÈÈÝ£º

ʹÓÃselect()ÒªÁì

LaravelµÄselect()ÒªÁìÊÇ×î»ù±¾µÄ¼ìË÷Ìض¨×ֶεÄÒªÁì¡£ÎÒÃÇ¿ÉÒÔͨ¹ý¸ÃÒªÁìÖ¸¶¨Òª·µ»ØµÄ×ֶΡ£ÀýÈ磬ÏÂÃæÊÇÒ»¸öÅÌÎÊusers±íÖÐnameºÍemail×ֶεÄʾÀý£º

$users = DB::table('users')
             ->select('name', 'email')
             ->get();

µÇ¼ºó¸´ÖÆ

´ÓÉÏÃæµÄÓï¾äÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ÎÒÃÇÖ»ÐèÒªÔÚselect()ÒªÁìÖÐת´ïÒª¼ìË÷µÄ×ֶμ´¿É¡£Õâ»á·µ»ØÒ»¸ö°üÀ¨nameºÍemail×Ö¶ÎÖµµÄÊý×é¡£

ʹÓÃaddSelect()ÒªÁì

ÔÚijЩÇéÐÎÏ£¬ÎÒÃÇ¿ÉÄÜÐèÒªÔÚÏÖÓеÄÅÌÎʲÙ×÷ÖÐÌí¼ÓÒª·µ»ØµÄ×ֶΡ£Õâʱ¿ÉÒÔʹÓÃaddSelect()ÒªÁì¡£ÀýÈ磬ÏÂÃæÊÇÒ»¸öÅÌÎÊusers±íÖÐËùÓÐ×ֶΣ¬²¢Ìí¼ÓÒ»¸öcountry×ֶεÄʾÀý£º

$users = DB::table('users')
             ->addSelect('country')
             ->get();

µÇ¼ºó¸´ÖÆ

´ÓÉÏÃæµÄÓï¾äÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ÎÒÃÇÖ»ÐèÒªÔÚaddSelect()ÒªÁìÖÐת´ïÒªÌí¼ÓµÄ×ֶμ´¿É¡£Õâ»á·µ»ØÒ»¸ö°üÀ¨ËùÓÐ×Ö¶ÎÖµºÍcountry×Ö¶ÎÖµµÄÊý×é¡£

ʹÓÃpluck()ÒªÁì

ÈôÊÇÎÒÃÇÖ»ÐèÒª¼ìË÷Ò»¸öÌض¨×ֶεÄÖµ£¬¿ÉÒÔʹÓÃpluck()ÒªÁì¡£ÀýÈ磬ÏÂÃæÊÇÒ»¸öÅÌÎÊusers±íÖÐemail×Ö¶ÎÖµµÄʾÀý£º

$email = DB::table('users')->where('name', 'John')->pluck('email');

µÇ¼ºó¸´ÖÆ

´ÓÉÏÃæµÄÓï¾äÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ÎÒÃÇÖ»ÐèÒªÔÚpluck()ÒªÁìÖÐת´ïÒª¼ìË÷µÄ×ֶμ´¿É¡£Õâ»á·µ»Ø¸Ã×ֶεÄÖµ¡£

ʹÓÃvalue()ÒªÁì

Óëpluck()ÒªÁìÀàËÆ£¬value()ÒªÁìÒ²ÊÇÖ»¼ìË÷Ò»¸öÌض¨×ֶεÄÖµ¡£¿ÉÊÇ£¬Óëpluck()ÒªÁì²î±ðµÄÊÇ£¬Ëü·µ»ØµÄÊÇÒ»¸öµ¥¶ÀµÄÖµ£¬¶ø²»ÊÇÒ»¸öÊý×é¡£ÀýÈ磬ÏÂÃæÊÇÒ»¸öÅÌÎÊusers±íÖÐemail×Ö¶ÎÖµµÄʾÀý£º

$email = DB::table('users')->where('name', 'John')->value('email');

µÇ¼ºó¸´ÖÆ

´ÓÉÏÃæµÄÓï¾äÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ÎÒÃÇÖ»ÐèÒªÔÚvalue()ÒªÁìÖÐת´ïÒª¼ìË÷µÄ×ֶμ´¿É¡£Õâ»á·µ»Ø¸Ã×ֶεÄÖµ¡£

ʹÓÃselectRaw()ºÍwhereIn()ÒªÁì

ÉÐÓÐÒ»ÖÖ¸ü¸ß¼¶µÄÒªÁì¿ÉÒÔ¼ìË÷Ìض¨×ֶΡ£ÈôÊÇÎÒÃÇÐèÒª´Ó¶à¸ö±íÖмìË÷Êý¾Ý£¬²¢Æ¾Ö¤Ä³Ð©Ìõ¼þ¹ýÂËÊý¾Ý£¬Ôò¿ÉÒÔʹÓÃselectRaw()ÒªÁì¡£ÀýÈ磬ÏÂÃæÊÇÒ»¸öÅÌÎÊorders±íºÍproducts±íÖÐÌض¨×ֶεÄʾÀý£º

$orders = DB::table('orders')
                ->selectRaw('price * ? as total_price', [2])
                ->whereIn('id', [1, 2, 3])
                ->get();

µÇ¼ºó¸´ÖÆ

´ÓÉÏÃæµÄÓï¾äÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½£¬ÎÒÃÇÔÚselectRaw()ÒªÁìÖбàдÁËÒ»¸öԭʼSQLÅÌÎÊÀ´ÅÌËã×ܼÛÇ®¡£ÎÒÃÇ»¹Ê¹ÓÃwhereIn()ÒªÁìÖ¸¶¨Òª¼ìË÷µÄorders id£¬²¢Ê¹ÓÃget()ÒªÁì»ñÈ¡ÅÌÎÊЧ¹û¡£

×ܽá

ÔÚLaravelÖоÙÐÐÊý¾Ý¿âÅÌÎÊʱ£¬Ö¸¶¨Òª¼ìË÷µÄÌض¨×Ö¶ÎÊÇÒ»¸öºÜ³£¼ûµÄÐèÇó¡£ÎÒÃÇ¿ÉÒÔʹÓÃselect()¡¢addSelect()¡¢pluck()¡¢value()ºÍselectRaw()µÈÒªÁìÀ´ÊµÏÖÕâ¸öÄ¿µÄ¡£ÕâЩҪÁìÌṩÁ˲î±ðµÄÎÞаÐԺ͹¦Ð§£¬ÈÃÎÒÃÇ¿ÉÒÔƾ֤ÏêϸµÄÅÌÎÊÐèÇóÑ¡ÔñÊʺϵÄÒªÁì¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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