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

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