laravel ÅÌÎÊ×î´óµÄ
laravelÅÌÎÊ×î´óµÄÊý¾Ý
LaravelÊÇÒ»¸öΪwebÒÕÊõ¼ÒÉè¼ÆµÄPHP Web¿ò¼Ü£¬Ëü²»µ«ÓÐÐí¶àÓÅÒìµÄ¹¦Ð§£¬²¢ÇÒËüµÄÓïÑÔÇкÏÒÕÊõ¼ÒÃǵÄÍ·ÄÔ·½·¨¡£ÔÚLaravelÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃEloquent ORMÀ´Ó³ÉäÊý¾Ý¿â¡£EloquentÊÇÒ»ÖÖÓÅÑŵġ¢Á÷ͨµÄ¡¢ÓÃÓÚÔÚLaravelÖнç˵ºÍÖ´ÐÐÊý¾Ý¿â²Ù×÷µÄÓïÑÔ¡£
ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚLaravelÖÐÅÌÎÊ×î´óµÄÊý¾Ý¡£ÔÚ±¾ÀýÖУ¬ÎÒÃǽ«Ê¹ÓÃÒ»¸öproducts±í¡£Õâ¸ö±íÓÐÒ»¸öÃûΪ¡°price¡±µÄÁУ¬ÎÒÃǽ«ÔÚÕâÁÐÖвéÕÒ×î´óµÄ¼ÛÇ®¡£
Ê×ÏÈ£¬ÎÒÃÇÐèҪȷ¶¨Äĸö°æ±¾µÄLaravel¿ò¼ÜÎÒÃǽ«Ê¹Óá£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«Ê¹ÓÃLaravel 8¡£ÔÚLaravel 8ÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÁ½ÖÖ·½·¨ÅÌÎÊ×î´óÖµ£ºÊ¹ÓÃÔʼÅÌÎÊ»òʹÓÃEloquent ORM¡£
ʹÓÃÔʼÅÌÎÊ
ʹÓÃÔʼÅÌÎÊ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏ´úÂëÀ´ÅÌÎÊ×î´óÖµ£º
$maxPrice = DB::table('products')->max('price');
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃDBÃÅÃæÀ´»á¼ûÊý¾Ý¿â¡£È»ºó£¬Ê¹ÓÃtable()ÒªÁìÖ¸¶¨ÎÒÃÇÒªÅÌÎʵıí¸ñ¡£×îºó£¬ÎÒÃÇŲÓÃmax()ÒªÁìÀ´»ñÈ¡ÁеÄ×î´óÖµ¡£
ÎÒÃÇ»¹¿ÉÒÔÔÚÅÌÎÊÖÐʹÓÃwhere()ÒªÁìÀ´Ìí¼ÓɸѡÌõ¼þ¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔÅÌÎʼÛÇ®´óÓÚ100µÄÉÌÆ·µÄ×î¸ß¼ÛÇ®£º
$maxPrice = DB::table('products')->where('price', '>', 100)->max('price');
µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½£¬ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÔÚwhere()ÒªÁìÖÐÌí¼ÓÁËÒ»¸öÓë²Ù×÷·ûºÍÒ»¸öÖµÀ´Ö¸¶¨É¸Ñ¡Ìõ¼þ¡£
ʹÓÃEloquent ORM
ÈôÊÇÄúÏëͨ¹ýEloquent ORMÅÌÎÊ×î´óÖµ£¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
$maxPrice = Product::max('price');
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃProductÄ£×ÓÀ´²Ù×÷products±í¡£È»ºó£¬ÎÒÃÇŲÓÃmax()ÒªÁìÀ´»ñÈ¡ÁеÄ×î´óÖµ¡£
ÓëÔʼÅÌÎÊÀàËÆ£¬ÎÒÃÇ¿ÉÒÔʹÓÃwhere()ÒªÁìÀ´Ìí¼ÓɸѡÌõ¼þ£º
$maxPrice = Product::where('price', '>', 100)->max('price');
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇʹÓÃÁËwhere()ÒªÁìÌí¼ÓÁËÒ»¸öÓë²Ù×÷·ûºÍÒ»¸öÖµÀ´Ö¸¶¨É¸Ñ¡Ìõ¼þ¡£
×ܽá
ÒÔÉϾÍÊÇÔÚLaravelÖÐÅÌÎÊ×î´óÖµµÄÁ½ÖÖ²î±ðÒªÁì¡£ÈôÊÇÄúϲ»¶¸ü¶àÔʼµÄ²Ù×÷ºÍ¸üºÃµÄÐÔÄÜ£¬ÄÇôʹÓÃÔʼÅÌÎÊ¿ÉÄÜÊÇÒ»¸ö²»´íµÄÑ¡Ôñ¡£¿ÉÊÇ£¬ÈôÊÇÄú¸üϲ»¶Ê¹ÓÃÄ£×Ӻ͸ü×ÔÈ»µÄÓï·¨£¬ÄÇôʹÓÃEloquent ORM¿ÉÄܸüÊʺÏÄú¡£ÔÚÏÖʵӦÓÃÖУ¬Äú¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóºÍʹÓÃÏ°¹ßÀ´Ñ¡ÔñÄÄÖÖÒªÁì¡£
ÒÔÉϾÍÊÇlaravel ÅÌÎÊ×î´óµÄµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡