尊龙凯时人生就是搏

laravel ÅÌÎÊijЩ×Ö¶Î

laravelÊÇÒ»¸öÊ¢ÐеÄphp web¿ª·¢¿ò¼Ü£¬ËüÌṩÁËÐí¶à±ã½ÝµÄ¹¦Ð§ºÍ¹¤¾ßÀ´¼ò»¯¿ª·¢Á÷³Ì¡£ÆäÖÐÒ»¸ö×î³£ÓõĹ¦Ð§ÊÇÅÌÎÊÊý¾Ý¿âÖеÄÊý¾Ý¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÖÐÅÌÎÊijЩ×ֶΡ£

Ê×ÏÈ£¬ÈÃÎÒÃǼÙÉèÎÒÃÇÓÐÒ»¸öÃûΪ¡°users¡±µÄ±í£¬ÆäÖаüÀ¨ÒÔÏÂ×ֶΣºid¡¢name¡¢email¡¢password¡¢created_at ºÍ updated_at¡£ÏÖÔÚÎÒÃÇÒªÅÌÎÊËùÓÐÓû§µÄÃû³ÆºÍµç×ÓÓʼþ£¬ÒԱ㽫ÕâЩÐÅϢչʾÔÚÍøÕ¾µÄÓû§ÁбíÉÏ¡£

ÔÚLaravelÖУ¬ÎÒÃÇʹÓÃEloquent ORMÀ´ÓëÊý¾Ý¿â¾ÙÐн»»¥¡£ORM´ú±í¹¤¾ß¹ØϵӳÉ䣬ËüÔÊÐíÎÒÃÇʹÓÃPHP¹¤¾ßÀ´ÌåÏÖÊý¾Ý¿â±íÖеÄÐС£ÒªÅÌÎÊijЩ×ֶΣ¬ÎÒÃÇ¿ÉÒÔʹÓÃEloquentµÄselectÒªÁì¡£

ÏÂÃæÊÇÒ»¸öʾÀý´úÂ룬ÑÝʾÔõÑùÅÌÎÊ¡°users¡±±íÖÐËùÓÐÓû§µÄÃû³ÆºÍµç×ÓÓʼþ£º

use AppUser;

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

foreach ($users as $user) {
    echo $user->name . ' - ' . $user->email . '<br>';
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁËUserÄ£×ÓÀàÀ´ÅÌÎÊÊý¾Ý¿â¡£Ê×ÏÈ£¬ÎÒÃÇʹÓÃselectÒªÁìÀ´Ö¸¶¨ÎÒÃÇÒªÅÌÎʵÄ×ֶΣ¬È»ºóʹÓÃgetÒªÁìÀ´»ñȡЧ¹û¡£×îºó£¬ÎÒÃÇʹÓÃforeachÑ­»·À´±éÀúЧ¹û£¬²¢Êä³öÿ¸öÓû§µÄÃû³ÆºÍµç×ÓÓʼþ¡£

ÈôÊÇÄúÒªÅÌÎʶà¸ö±í£¬²¢ÇÒÕâЩ±íÖÐÓÐÏàͬµÄ×Ö¶ÎÃû³Æ£¬ÄÇôÄúÐèҪʹÓñíÓÖÃûÀ´Çø·ÖËüÃÇ¡£ÏÂÃæÊÇÒ»¸öʾÀý´úÂ룬ÑÝʾÔõÑùÅÌÎÊ¡°users¡±±íºÍ¡°orders¡±±íÖÐËùÓÐÓû§µÄÃû³ÆºÍ¶©µ¥ºÅÂ룺

use AppUser;
use AppOrder;

$users = User::select('users.name', 'orders.order_number')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->get();

foreach ($users as $user) {
    echo $user->name . ' - ' . $user->order_number . '<br>';
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁËjoinÒªÁìÀ´ÅþÁ¬¡°users¡±±íºÍ¡°orders¡±±í£¬²¢Ê¹ÓÃselectÒªÁìÀ´Ö¸¶¨ÅÌÎÊ×ֶΡ£ÎÒÃÇʹÓÃÁ˱íÓÖÃû¡°users¡±ºÍ¡°orders¡±£¬ÒÔÇø·ÖÕâÁ½¸ö±íÖоßÓÐÏàͬÃû³ÆµÄ×ֶΡ£

×ÜÖ®£¬ÔÚLaravelÖÐÅÌÎÊijЩ×Ö¶ÎÊǺÜÊǼòÆӵġ£Äú¿ÉÒÔʹÓÃEloquent ORMÌṩµÄselectÒªÁìÀ´ÅÌÎÊÖ¸¶¨µÄ×ֶΣ¬ÉõÖÁ¿ÉÒÔÅþÁ¬¶à¸ö±íÀ´»ñÈ¡ËùÐèµÄЧ¹û¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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