×ðÁú¿­Ê±¹ÙÍøµÇ¼

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
ÍøÕ¾µØͼ