laravel ÅÌÎÊ»ñÈ¡Êý×é
laravelÊÇÒ»¿îÊ¢ÐеÄphp webÓ¦ÓóÌÐò¿ò¼Ü¡£ËüÌṩÁËÐí¶à¹¤¾ßºÍº¯Êý£¬¿ÉÒÔÇáËɵش¦ÀíÊý¾Ý¿âÅÌÎÊ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÖÐʹÓÃÅÌÎÊÀ´»ñÈ¡Êý×é¡£
ÔÚLaravelÖУ¬¿ÉÒÔʹÓÃDBÀàÀ´Ö´ÐÐÊý¾Ý¿âÅÌÎÊ¡£¸ÃÀàÌṩÁËÐí¶à±ã½ÝµÄº¯Êý£¬ÓÃÓÚÖ´ÐÐÖÖÖÖÀàÐ͵ÄÅÌÎÊ¡£¿ÉÒÔʹÓÃDB::table()º¯Êý»ñÈ¡Ò»¸öÅÌÎʹ¹½¨Æ÷£¬Ê¹ÓÃËüÀ´¹¹½¨ÖØ´óµÄÅÌÎÊ¡£
ÒÔÏÂÊÇÒ»¸öʾÀý£¬Õ¹Ê¾ÔõÑùʹÓÃÅÌÎʹ¹½¨Æ÷´ÓÊý¾Ý¿âÖлñÈ¡Ò»¸öÊý×飺
$users = DB::table(‘users’)->pluck(‘name’);
ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃÇͨ¹ýʹÓÃpluck()º¯ÊýÀ´»ñÈ¡´Óusers±íÖлñÈ¡name×ֶεÄÊý×é¡£ÎÒÃÇʹÓÃDB::table()º¯Êý»ñÈ¡ÁËÒ»¸öÅÌÎʹ¹½¨Æ÷£¬È»ºóʹÓÃËüÀ´¹¹½¨ÅÌÎÊ¡£
ÒÔÏÂÊÇÁíÒ»¸öʾÀý£¬ËüչʾÔõÑùʹÓÃÅÌÎʹ¹½¨Æ÷À´»ñÈ¡¶à¸ö×ֶεÄÊý×飺
$users = DB::table(‘users’)->select(‘name’, ’email’)->get();
ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃÇʹÓÃselect()º¯ÊýÀ´Ö¸¶¨ÎÒÃÇÒª»ñÈ¡µÄ×ֶΡ£È»ºóʹÓÃget()º¯ÊýÀ´Ö´ÐÐÅÌÎʲ¢·µ»ØЧ¹ûÊý×é¡£
ËäÈ»£¬ÎÒÃÇÒ²¿ÉÒÔÔÚÅÌÎÊÖÐʹÓÃÔ¼ÊøÌõ¼þ£¬ÀýÈçʹÓÃwhere()º¯ÊýÀ´ÏÞÖÆÅÌÎÊЧ¹û£º
$users = DB::table(‘users’)->where(‘name’, ‘John’)->get();
ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃÇʹÓÃwhere()º¯ÊýÀ´Ô¼ÊøÅÌÎÊ£¬Ö»·µ»Øname×Ö¶ÎֵΪJohnµÄÐС£
ÎÒÃÇ»¹¿ÉÒÔʹÓÃorderBy()º¯Êý¶ÔЧ¹û¾ÙÐÐÅÅÐò£º
$users = DB::table(‘users’)->orderBy(‘name’, ‘desc’)->get();
ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃÇʹÓÃorderBy()º¯Êý½«Ð§¹ûƾ֤name×ֶξÙÐе¹ÐòÅÅÐò¡£
ÐèҪעÖصÄÊÇ£¬ÉÏÊöʾÀýÖеÄget()º¯Êý·µ»ØµÄÊÇÒ»¸öÊý×鹤¾ß¡£ÈôÊÇÒª½«Êý×éת»¯ÎªÍ¨Ë×µÄPHPÊý×飬¿ÉÒÔʹÓÃtoArray()º¯Êý£º
$users = DB::table(‘users’)->select(‘name’, ’email’)->get()->toArray();
ÔÚÒÔÉÏʾÀýÖУ¬ÎÒÃÇÔÚget()º¯ÊýºóʹÓÃtoArray()º¯Êý£¬½«»ñÈ¡µ½µÄ¹¤¾ßת»¯ÎªÍ¨Ë×µÄPHPÊý×é¡£
×ܽáһϣ¬ÒÔÉÏÊÇʹÓÃLaravelÅÌÎʹ¹½¨Æ÷»ñÈ¡Êý×éµÄһЩʾÀý¡£ÕâЩº¯Êý¿ÉÒÔ×ÊÖúÎÒÃÇÇáËɵع¹½¨ÖØ´óµÄÅÌÎÊ£¬ÒÔ»ñÈ¡ÎÒÃÇÐèÒªµÄÊý¾Ý¡£LaravelÇ¿Ê¢µÄÅÌÎʹ¦Ð§ÊÇÕâ¸ö¿ò¼ÜÊܵ½ÆÕ±é½Ó´ýµÄÖ÷ÒªÔµ¹ÊÔÓÉÖ®Ò»¡£
ÒÔÉϾÍÊÇlaravel ÅÌÎÊ»ñÈ¡Êý×éµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡