Laravel TinkerÖÐÔõÑùɾ³ýÊý¾Ý
laravel tinker ÊÇÒ»¸öÌṩ½»»¥Ê½ÏÂÁîÐнçÃæµÄ¹¤¾ß£¬Ê¹µÃÔÚ laravel Ó¦ÓÃÖвÙ×÷Êý¾Ý¿ÉÒÔ¸üÀû±ã¡£±¾ÎĽ«ÏÈÈÝÔÚ laravel tinker ÖÐÔõÑùɾ³ýÊý¾Ý¡£
Ê×ÏÈ£¬ÄãÐèÒª·¿ªÖն˲¢½øÈëµ½ÄãµÄ Laravel Ó¦ÓÃËùÔÚµÄĿ¼ÖС£È»ºóÊäÈëÒÔÏÂÏÂÁî½øÈë Tinker£º
php artisan tinker
µÇ¼ºó¸´ÖÆ
½Ó×Å£¬ÎÒÃÇ¿ÉÒÔʹÓà Eloquent À´²Ù×÷ÎÒÃǵÄÊý¾Ý¿â¡£¼ÙÉèÎÒÃÇÓÐÒ»¸öÃûΪ users µÄ±í¸ñ£¬²¢ÇÒÎÒÃÇÏëҪɾ³ýÆäÖеÄÒ»ÌõÊý¾Ý¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÕÒµ½ÎÒÃÇҪɾ³ýµÄÊý¾Ý¡£¿ÉÒÔʹÓà find ÒªÁìͨ¹ýÖ÷¼ü²éÕÒÊý¾Ý¡£ÀýÈ磺
$user = App\User::find(1);
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁÔÚ users ±í¸ñÖвéÕÒÖ÷¼üΪ 1 µÄÊý¾Ý£¬²¢½«Æ丳ֵ¸ø $user ±äÁ¿¡£
½Ó×Å£¬ÎÒÃÇ¿ÉÒÔʹÓà delete ÒªÁìɾ³ýÕâÌõÊý¾Ý¡£ÀýÈ磺
$user->delete();
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁ´ÓÊý¾Ý¿âÖÐɾ³ý $user ±äÁ¿Ëù´ú±íµÄÊý¾Ý¡£
ÈôÊÇÎÒÃÇÏëҪͬʱɾ³ý¶àÌõÊý¾Ý£¬ÎÒÃÇ¿ÉÒÔʹÓà where ÒªÁìÀ´ÅÌÎÊҪɾ³ýµÄÊý¾Ý£¬²¢Ê¹Óà delete ÒªÁ콫ËüÃÇɾ³ý¡£ÀýÈ磺
App\User::where('id', '>', 10)->delete();
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁ´Ó users ±í¸ñÖÐɾ³ýËùÓÐÖ÷¼ü´óÓÚ 10 µÄÊý¾Ý¡£
ÁíÍ⣬ÈôÊÇÄãÏëÒªÍêÈ«Çå¿ÕÒ»¸ö±í¸ñÖеÄËùÓÐÊý¾Ý£¬¿ÉÒÔʹÓà truncate ÒªÁì¡£ÀýÈ磺
App\User::truncate();
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁ»áɾ³ý users ±í¸ñÖеÄËùÓÐÊý¾Ý¡£
×îºó£¬µ±ÄãÍê³ÉÁËËùÓвÙ×÷£¬¿ÉÒÔʹÓà exit ÏÂÁîÍ˳ö Tinker¡£
×ܽáÀ´Ëµ£¬ÔÚ Laravel Tinker ÖÐɾ³ýÊý¾ÝÐèÒªÒÔÏ°취£º
ʹÓà find ÒªÁì²éÕÒҪɾ³ýµÄÊý¾Ý²¢½«Æ丳ֵ¸øÒ»¸ö±äÁ¿¡£
ʹÓà delete ÒªÁìɾ³ýµ¥ÌõÊý¾Ý¡£
ʹÓà where ÒªÁìÅÌÎÊҪɾ³ýµÄÊý¾Ý£¬²¢Ê¹Óà delete ÒªÁìɾ³ý¶àÌõÊý¾Ý¡£
ʹÓà truncate ÒªÁìɾ³ý±í¸ñÖеÄËùÓÐÊý¾Ý¡£
Í˳ö Tinker¡£
ÔÚ²Ù×÷Êý¾Ýʱһ¶¨ÒªÐ¡ÐÄ£¬ÒÔ·ÀʧÉ÷ɾ³ýÁËÖ÷ÒªµÄÊý¾Ý¡£ÇмDZ¸·ÝºÃÊý¾ÝºóÔÙ¾ÙÐвÙ×÷¡£
ÒÔÉϾÍÊÇLaravel TinkerÖÐÔõÑùɾ³ýÊý¾ÝµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡