laravelÄ£×ÓÔõôÔöɾ¸Ä²é
ÔÚlaravelÖУ¬Ä£×ÓÊÇÓÃÓÚÖÎÀíÓ¦ÓóÌÐòÊý¾ÝµÄ»ù±¾¹¤¾ß£¬¾³£±»ÓÃÓÚ´¦ÀíÓëÊý¾Ý¿âÏà¹ØµÄ²Ù×÷¡£Ä£×Ó¿ÉÒÔÈÃÓû§¸üÀû±ã¡¢¸ü¿ìËÙµØÖ´ÐÐÊý¾Ý¿â²Ù×÷£¬Ê¹³ÌÐòÔ½·¢Ò×ÓÚά»¤¡£
ÄÇô£¬ÔÚLaravelÖУ¬ÔõÑùʹÓÃÄ£×ÓÀ´¾ÙÐÐÔöɾ¸Ä²é²Ù×÷ÄØ£¿½ÓÏÂÀ´£¬ÎÒÃǽ«ÒÀ´Î½âËÃ÷ÈÕâЩ²Ù×÷¡£
ÔöÌí
ÔÚLaravelÖУ¬ÐÂÔöÊý¾ÝÊÇͨ¹ýÄ£×ÓµÄcreateÒªÁìÍê³ÉµÄ¡£ÀýÈ磬ÎÒÃÇÓÐÒ»¸öUsersÄ£×Ó£¬Æä¶ÔÓ¦µÄÊý¾Ý±íΪusers£¬ÏÖÔÚÐèÒªÐÂÔöÒ»¸öÓû§£º
$user = Users::create([ 'name' => 'Tom', 'age' => 25, 'gender' => 'male' ]);
µÇ¼ºó¸´ÖÆ
ÕâÀcreateÒªÁì½ÓÊÜÒ»¸öÊý×飬Êý×éµÄ¼üΪ±íÖеÄÁÐÃû£¬ÖµÎªÒªÐÂÔöµÄÊý¾Ý¡£ÔÚÐÂÔöÊý¾Ýʱ£¬Laravel»á×Ô¶¯´¦ÀíÊý¾Ý¿âµÄʱ¼ä´ÁÁУ¨created_atºÍupdated_at£©¡£
ËäÈ»£¬ÈôÊÇÐèÒªÐÂÔö¶àÌõÊý¾Ý£¬ÎÒÃÇÒ²¿ÉÒÔʹÓÃinsertÒªÁì¡£insertÒªÁì½ÓÊÜÒ»¸ö¶þάÊý×飬ÀàËÆÓÚÏÂÃæÕâÑù£º
Users::insert([ [ 'name' => 'Tom', 'age' => 25, 'gender' => 'male' ], [ 'name' => 'Lucy', 'age' => 23, 'gender' => 'female' ], // ... ]);
µÇ¼ºó¸´ÖÆ
ÐÞ¸Ä
ÔÚLaravelÖУ¬ÐÞ¸ÄÊý¾ÝÊÇͨ¹ýÄ£×ÓʵÀýµÄsaveÒªÁìÍê³ÉµÄ¡£ÀýÈ磬ÎÒÃÇÐèÒªÐÞ¸ÄÉÏÃæн¨µÄÓû§µÄÐÕÃû£º
$user->name = 'Jerry'; $user->save();
µÇ¼ºó¸´ÖÆ
ÕâÀÎÒÃÇÊ×ÏÈͨ¹ý$user->nameÀ´ÐÞ¸ÄÓû§µÄÐÕÃû£¬È»ºóŲÓÃsaveÒªÁ콫Ð޸ĺóµÄÊý¾ÝÉúÑĵ½Êý¾Ý¿âÖС£
ÈôÊÇÐèÒªÅúÁ¿ÐÞ¸ÄÊý¾Ý£¬ÎÒÃÇ¿ÉÒÔʹÓÃÄ£×ÓµÄupdateÒªÁ죬ÀýÈ磬½«ËùÓÐÄêËêΪ25ËêµÄÓû§ÐÕÃûÐÞ¸ÄΪJerry£º
Users::where('age', 25)->update(['name' => 'Jerry']);
µÇ¼ºó¸´ÖÆ
ɾ³ý
ÔÚLaravelÖУ¬É¾³ýÊý¾ÝÒ²ºÜ¼òÆÓ£¬Í¨¹ýÄ£×ÓʵÀýµÄdeleteÒªÁì¼´¿É¡£ÀýÈ磬ÎÒÃÇÐèҪɾ³ýÉÏÃæÐÂÔöµÄÓû§£º
$user->delete();
µÇ¼ºó¸´ÖÆ
ÕâÀÎÒÃÇÖ±½ÓŲÓÃdeleteÒªÁì¼´¿Éɾ³ý¸ÃÄ£×ÓʵÀý¡£
ÈôÊÇÐèÒªÅúÁ¿É¾³ýÊý¾Ý£¬ÎÒÃÇ¿ÉÒÔʹÓÃÄ£×ÓµÄdestroyÒªÁ죬ÀýÈ磬ɾ³ýËùÓÐÄêËêΪ25ËêµÄÓû§£º
Users::where('age', 25)->delete();
µÇ¼ºó¸´ÖÆ
ÅÌÎÊ
ÔÚLaravelÖУ¬ÅÌÎÊÊý¾ÝÊÇͨ¹ýÄ£×ÓµÄgetÒªÁì¡¢takeÒªÁì¡¢whereÒªÁìµÈÀ´Íê³ÉµÄ¡£
ÀýÈ磬ÎÒÃÇÐèÒªÅÌÎÊËùÓеÄÓû§£º
$users = Users::all();
µÇ¼ºó¸´ÖÆ
ÕâÀÎÒÃÇŲÓÃallÒªÁì¼´¿É»ñµÃËùÓÐÓû§µÄÊý¾Ý¡£
ÈôÊÇÐèҪɸѡÊý¾Ý£¬ÎÒÃÇ¿ÉÒÔʹÓÃwhereÒªÁ죬ÀýÈ磬ÅÌÎÊËùÓÐÄêËê´óÓÚ¼´ÊÇ20µÄÓû§£º
$users = Users::where('age', '>=', 20)->get();
µÇ¼ºó¸´ÖÆ
±ðµÄ£¬ÔÚLaravelÖУ¬»¹ÌṩÁËÐí¶àÆäËûÅÌÎÊÒªÁ죬ÀýÈ磺first¡¢find¡¢pluck¡¢countµÈ¡£ÕâÀï²»ÔÙÏê½â£¬¿É²Î¿¼¹Ù·½Îĵµ¾ÙÐÐѧϰ¡£
×ܽá
ͨ¹ý±¾ÎĵÄÏÈÈÝ£¬ÎÒÃÇÏàʶµ½£¬LaravelµÄÄ£×ÓÌṩÁ˸»ºñµÄAPI£¬¿ÉÒÔ´ó´ó¼ò»¯ÓëÊý¾Ý¿âµÄ½»»¥£¬Ê¹¿ª·¢Ô½·¢ÓÐÓᢱã½Ý¡£Ï£Íû±¾ÎĶÔLaravel¿ª·¢ÕßÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇlaravelÄ£×ÓÔõôÔöɾ¸Ä²éµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡