尊龙凯时人生就是博

withÓ÷¨laravel

Ëæ×Ålaravel³ÉΪphp¿ª·¢ÖÐ×îÊܽӴýµÄ¿ò¼ÜÖ®Ò» £¬Ô½À´Ô½¶àµÄ¿ª·¢Õß×îÏÈʹÓÃËüÀ´¹¹½¨¸ßÐÔÄÜ¡¢¿ÉÀ©Õ¹µÄwebÓ¦ÓóÌÐò¡£ÔÚlaravelÖÐ £¬Ê¹Óá°with¡±ÒªÁì¿ÉÒÔÇáËɵؾÙÐжà´ÎÊý¾Ý¿âÅÌÎÊ £¬Õâ¿ÉÒÔÓÐÓõØÌá¸ßÐÔÄܺÍïÔÌ­ÅÌÎÊʱ¼ä¡£±¾ÎĽ«ÏÈÈÝlaravelÖеġ°with¡±ÒªÁìµÄÓ÷¨¼°ÆäÓÅÊÆ¡£

Ò»¡¢Ê²Ã´ÊÇ¡°with¡±ÒªÁì

ÔÚLaravelÖÐ £¬Ê¹Óá°with¡±ÒªÁì¿ÉÒÔÇáËɵؽâ¾ö¡°N+1ÅÌÎÊ¡±ÎÊÌâ £¬¼´µ±ÄãÏëÅÌÎÊÒ»¸öÄ£×Ó¼°Æä¹ØÁªÄ£×Óʱ £¬ÈôÊÇÄãʹÓÃÁËÑ­»·ÅÌÎÊ £¬ÄÇô¾Í»á±¬·¢´ó×ÚµÄÅÌÎÊÓï¾ä £¬´Ó¶øµ¼ÖÂÐÔÄÜϽµ¡£Ê¹Óá°with¡±ÒªÁì £¬¿ÉÒÔÈÃLaravelÒ»´ÎÅÌÎʳöËùÓйØÁªÄ£×ÓµÄÊý¾Ý £¬Õ⽫´ó´óÌá¸ßÐÔÄܺÍïÔÌ­ÅÌÎÊʱ¼ä¡£

¶þ¡¢¡°with¡±ÒªÁìµÄÓ÷¨

¡°with¡±ÒªÁì¿ÉÒÔÔÚÅÌÎÊÆ÷ÖÐʹÓà £¬Ò²¿ÉÒÔÔÚÄ£×ÓÖÐʹÓá£ÎÒÃÇÏÈÀ´¿´¿´ÔÚÅÌÎÊÆ÷ÖÐʹÓá°with¡±ÒªÁìµÄÓï·¨£º

User::with('posts')->get();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂë¿ÉÒÔÃ÷ȷΪ£º¡°ÅÌÎÊÓû§ £¬²¢Ò»ÆðÅÌÎÊÿ¸öÓû§µÄËùÓÐÎÄÕ¡±¡£Õâ¶Î´úÂëÏÖʵÉÏÖ»Ö´ÐÐÁËÁ½¸öÅÌÎÊ £¬¼´Ò»´ÎÅÌÎÊÓû§ÒÔ¼°ËùÓÐÓû§¹ØÁªµÄÎÄÕ £¬¶ø²»ÊÇÿ¸öÓû§¶¼¾ÙÐÐÒ»´ÎÅÌÎÊ¡£

³ýÁ˼òÆӵĹØÁª £¬»¹¿ÉÒÔͨ¹ýת´ïÒ»¸öÄäÃûº¯ÊýÀ´¹ýÂËÅÌÎÊ¡£ÀýÈç £¬ÎÒÃÇ¿ÉÒÔÖ»ÅÌÎÊÓû§ÔÚ×î½üÒ»ÖÜÄÚÐû²¼µÄÎÄÕ£º

User::with(['posts' => function($query) {
    $query->where('created_at', '>=', Carbon::now()->subWeek());
}])->get();

µÇ¼ºó¸´ÖÆ

ͨ¹ýʹÓÃÄäÃûº¯Êý £¬ÎÒÃÇ¿ÉÒÔÖ¸¶¨Ìض¨Ä£×ӵĹØϵºÍ¹ýÂËÆ÷ £¬²¢ÇÒ¿ÉÒÔƾ֤ÐèÒªÁ´Ê½Å²Óöà¸ö¹ØÁª¡£ÀýÈç £¬ÔÚÒ»¸ö²©¿ÍÓ¦ÓóÌÐòÖÐ £¬ÎÒÃÇÏëÒªÅÌÎÊËùÓÐÎÄÕ¼°Æä×÷Õß¡¢Ì¸ÂÛÒÔ¼°Ì¸ÂÛµÄ×÷Õߣº

$posts = Post::with(['author', 'comments', 'comments.author'])->get();

µÇ¼ºó¸´ÖÆ

ÉÏÃæµÄ´úÂëÅÌÎÊÁËËùÓÐÎÄÕ¼°Æä×÷Õß¡¢Ì¸ÂÛºÍ̸ÂÛµÄ×÷Õß £¬Ö»Ö´ÐÐÁË3¸öÅÌÎÊ £¬¶ø²»ÊÇÿ´ÎÖ´ÐÐÒ»¸öÅÌÎÊ¡£Õ⽫´ó´óÌá¸ßÐÔÄܺÍïÔÌ­ÅÌÎÊʱ¼ä¡£

Èý¡¢¡°with¡±ÒªÁìµÄÓÅÊÆ

ʹÓá°with¡±ÒªÁìµÄÓÅÊÆÔÚÓÚËü¿ÉÒÔïÔÌ­Êý¾Ý¿âÅÌÎÊ´ÎÊý £¬Ìá¸ßÐÔÄܺÍïÔÌ­ÅÌÎÊʱ¼ä¡£µ±ÄãÐèÒªÅÌÎʶà¸ö¹ØÁªÄ£×Óʱ £¬Í¨¹ýʹÓá°with¡±ÒªÁì £¬Äã¿ÉÒÔÖ»Ö´ÐÐÒ»´ÎÅÌÎÊ £¬¶ø²»ÊÇΪÿ¸öÄ£×Óµ¥¶ÀÖ´ÐÐÒ»´ÎÅÌÎÊ¡£Õ⽫ïÔÌ­Êý¾Ý¿âÇëÇó £¬´Ó¶øÌá¸ßÐÔÄÜ¡£

ͬʱ £¬LaravelµÄ¡°with¡±ÒªÁìÄܹ»Í¨¹ýת´ïÄäÃûº¯ÊýÀ´¹ýÂËÅÌÎÊ £¬´Ó¶ø½øÒ»²½ÓÅ»¯ÅÌÎÊ¡£ÕâÒâζ×ÅÄã¿ÉÒÔƾ֤ÐèÒª½«¹ØϵºÍ¹ýÂËÆ÷Á´½ÓÔÚÒ»Æ𠣬²¢ÇÒ¿ÉÒÔÎÞаµØ¾ÙÐÐÅÌÎÊ £¬²¢»ñµÃ׼ȷµÄЧ¹û¡£

ËÄ¡¢×ܽá

LaravelµÄ¡°with¡±ÒªÁìÊÇÒ»ÖÖÓÅ»¯Êý¾Ý¿âÅÌÎʵÄÇ¿Ê¢¹¤¾ß £¬¿ÉÒÔïÔÌ­Êý¾Ý¿âÅÌÎÊ´ÎÊý £¬Ìá¸ßÐÔÄܺÍïÔÌ­ÅÌÎÊʱ¼ä¡£Óëµ¥¶ÀÅÌÎÊÿ¸ö¹ØÁªÄ£×ÓÏà±È £¬Ê¹Óá°with¡±ÒªÁì¿ÉÒÔ¸üºÃµØÖÎÀíºÍ´¦ÀíÏà¹ØÊý¾Ý £¬Ìá¸ßWebÓ¦ÓóÌÐòµÄÐÔÄܺͿÉÉìËõÐÔ¡£ÈôÊÇÄãÕýÔÚʹÓÃLaravel¹¹½¨WebÓ¦ÓóÌÐò £¬ÄÇô¡°with¡±ÒªÁ콫ÊÇÌá¸ßÅÌÎÊÐÔÄܵÄÖ÷Òª¹¤¾ßÖ®Ò»¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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