尊龙凯时人生就是搏

laravel ÅÌÎʼ¸¸ö×Ö¶Î

ÔÚ¿ª·¢ laravel Ó¦ÓóÌÐòʱ £¬ÅÌÎÊÊý¾Ý¿âÊÇÒ»¸ö·Ç¾­³£¼ûµÄ²Ù×÷ £¬ÓÈÆäÊǹØÓÚÄÇЩÐèÒª·ºÆð´ó×ÚÊý¾ÝµÄ web Ó¦ÓóÌÐò¡£¿ÉÊÇ £¬ÓÐʱÎÒÃÇÖ»ÐèҪѡÔñһЩÌض¨µÄÁÐ £¬¶ø²»ÊÇÕû¸ö±íÖеÄËùÓÐÁС£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ laravel ÖÐÅÌÎʼ¸¸ö×ֶΡ£

ʹÓÃÅÌÎʹ¹½¨Æ÷

Laravel ÌṩÁËÒ»¸öÇ¿Ê¢µÄÅÌÎʹ¹½¨Æ÷ £¬¿ÉÒÔ×ÊÖúÎÒÃÇÀû±ãµØÓëÊý¾Ý¿â¾ÙÐн»»¥¡£ÎÒÃÇ¿ÉÒÔʹÓà select ÒªÁìÀ´ÏÞÖÆÎÒÃÇËùÐèµÄÁС£

ÀýÈç £¬ÎÒÃÇÓÐÒ»¸ö users ±í £¬ÆäÖаüÀ¨ id £¬name ºÍ email Èý¸ö×ֶΡ£ÈôÊÇÎÒÃÇÖ»ÐèҪѡÔñÕâЩ×Ö¶ÎÖеÄÁ½¸ö £¬ÎÒÃÇ¿ÉÒÔÕâÑùд£º

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

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃÇʹÓà select ÒªÁìÖ¸¶¨ÁË name ºÍ email ÁС£·µ»ØµÄ $users ¹¤¾ß½«Ö»°üÀ¨ÕâÁ½¸öÁС£

ËäÈ» £¬ÎÒÃÇÒ²¿ÉÒÔÑ¡ÔñʹÓà select À´Ñ¡ÔñËùÓеÄÁÐ £¬È»ºóʹÓà exclude ÒªÁìÀ´É¨³ýÎÒÃDz»ÐèÒªµÄÁС£ÀýÈ磺

$users = DB::table('users')->select('*')->exclude('id')->get();

µÇ¼ºó¸´ÖÆ

ÔÚÕâ¸öÀý×ÓÖÐ £¬ÎÒÃÇÊ×ÏÈʹÓà select ÒªÁìÑ¡ÔñËùÓеÄÁÐ £¬È»ºóʹÓà exclude ÒªÁìɨ³ýµôÁË id ÁС£·µ»ØµÄ $users ¹¤¾ß½«Ö»°üÀ¨ name ºÍ email ÁС£

ʹÓà Eloquent

Eloquent ÊÇ Laravel ÖеÄÒ»¸ö ORM£¨¹¤¾ß¹ØϵӳÉ䣩¹¤¾ß £¬¿ÉÒÔ×ÊÖúÎÒÃǸüÀû±ãµØÔÚ PHP ÖвÙ×÷Êý¾Ý¿â¡£Eloquent ¾ßÓÐÓëÅÌÎʹ¹½¨Æ÷ÀàËƵÄÒªÁì £¬¿ÉÒÔÈÃÎÒÃÇÔÚÅÌÎÊÖнö°üÀ¨ËùÐèµÄÁС£

ÀýÈç £¬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öÃûΪ User µÄ Eloquent Ä£×Ó £¬Ëü¶ÔÓ¦×Å users ±í£º

namespace App;

use IlluminateDatabaseEloquentModel;

class User extends Model
{
    protected $table = 'users';
}

µÇ¼ºó¸´ÖÆ

È»ºó £¬ÎÒÃÇ¿ÉÒÔʹÓà select ÒªÁìÀ´½ö°üÀ¨ËùÐèµÄÁУº

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

µÇ¼ºó¸´ÖÆ

»òÕßʹÓà exclude ÒªÁìɨ³ý²»ÐèÒªµÄÁУº

$users = User::exclude('id')->get();

µÇ¼ºó¸´ÖÆ

ÕâЩҪÁìÓëÅÌÎʹ¹½¨Æ÷ÌṩµÄÒªÁìºÜÊÇÏàËÆ¡£

½áÂÛ

ÅÌÎÊÊý¾Ý¿âÊÇÒ»¸ö³£¼ûµÄ²Ù×÷ £¬¶øÔÚ Laravel ÖÐ £¬ÎÒÃÇ¿ÉÒÔʹÓÃÅÌÎʹ¹½¨Æ÷ºÍ Eloquent Ä£×ÓÀ´ÇáËɵØÏÞÖÆÎÒÃÇËùÐèµÄÁС£Õâ²»µ«¿ÉÒÔïÔÌ­Êý¾Ý´«ÊäµÄÊýÄ¿ £¬»¹¿ÉÒÔÌá¸ßÎÒÃÇÓ¦ÓóÌÐòµÄÐÔÄÜ¡£Ï£Íû±¾ÎĶÔÄãÓÐËù×ÊÖú¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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