laravelÉèÖÃË÷Òý
Ëæ×Å»¥ÁªÍøÊÖÒյĿìËÙÉú³¤£¬´ó×ÚµÄÊý¾ÝÒ»Ö±µÄ±»Éú²úºÍÀÛ»ý£¬ÔõÑù¸ßЧµÄÌáÈ¡Êý¾Ý¹ØÓÚÐí¶àÆóÒµºÍСÎÒ˽È˶øÑÔÖÁ¹ØÖ÷Òª¡£ÔÚmysqlÊý¾Ý¿âÖУ¬Ë÷ÒýÄܹ»×ÊÖúÎÒÃÇ¿ìËٵĶ¨Î»ºÍÅÌÎÊÊý¾Ý£¬Ìá¸ßÅÌÎÊЧÂÊ¡£±¾ÆªÎÄÕ½«ÏÈÈÝÔõÑùÔÚlaravel¿ò¼ÜÏÂÉèÖÃË÷Òý¡£
Ò»¡¢ÎªÊ²Ã´ÒªÉèÖÃË÷Òý
Ë÷ÒýÊÇÊý¾Ý¿âÖг£ÓõÄÒ»ÖÖÊý¾Ý½á¹¹£¬Í¨¹ýÔÚ±íÖÐÌìÉúÒ»¸öË÷Òý£¬¿ÉÒÔÈÃÊý¾Ý¿â¸ü¿ìµØ²éÕÒÐèÒªµÄÊý¾Ý£¬Ìá¸ßÅÌÎʵÄЧÂÊ¡£ÔÚMySQLÊý¾Ý¿âÖУ¬Ã¿ÕÅ±í¶¼¿ÉÒÔÉèÖöà¸öË÷Òý£¬Ë÷Òý¿ÉÒÔÆðµ½ÀàËÆÓÚ×ÖµäµÄ×÷Óã¬ÈÃÎÒÃÇ¿ÉÒÔ¸ü¿ìËÙµØÕÒµ½ÐèÒªµÄ¼Í¼¡£
µ±Êý¾Ý¿âÖеÄÊý¾ÝÁ¿½ÏÁ¿´óµÄʱ¼ä£¬ÈôÊÇûÓÐË÷Òý£¬Êý¾Ý¿â¾ÍÐèҪͨÅÌɨÃ裬Õâ»á´øÀ´ºÜ´óµÄÐÔÄÜÎÊÌâ¡£¶øͨ¹ýÍŽáË÷ÒýºÍSQLÅÌÎÊ£¬¾Í¿ÉÒÔ¿ìËٵػñÈ¡ÐèÒªµÄÊý¾Ý£¬´ó´óïÔÌÅÌÎʵÄʱ¼ä¡£
¶þ¡¢ÔÚLaravel¿ò¼ÜÏÂÉèÖÃË÷Òý
ÔÚLaravel¿ò¼ÜÏ£¬ÎÒÃÇ¿ÉÒÔʹÓúÏÊʵÄÒªÁìÀ´Îª±íÉèÖÃË÷Òý£¬³£ÓõÄÒªÁìÓÐÒÔÏÂÁ½ÖÖ£º
ʹÓÃǨáãÎļþ¾ÙÐÐË÷ÒýÉèÖÃ
ÔÚLaravel¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý±àдǨáãÎļþµÄ·½·¨À´¾ÙÐÐË÷ÒýµÄÉèÖá£ÏêϸµÄ°ì·¨ÈçÏ£º
Ê×ÏÈ£¬ÎÒÃÇÐèҪʹÓÃÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸öÃûΪcreate_example_tableµÄǨáãÎļþ£º
php artisan make:migration create_example_table --create=example
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÔÚǨáãÎļþÖУ¬ÎÒÃÇÐèҪʹÓÃÒÔϵÄÓï¾äÀ´Îª±íÀý×ÓexampleÉèÖÃË÷Òý£º
public function up() { Schema::create('example', function (Blueprint $table) { $table->id(); $table->string('name'); $table->string('email')->unique(); $table->index(['name', 'email']); }); }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöµÄÓï¾äÖУ¬ÎÒÃÇʹÓÃÁËindexÒªÁìÀ´Îª±íÃûΪexampleµÄ±íÉèÖÃË÷Òý£¬Ë÷ÒýµÄ×Ö¶ÎΪnameºÍemail£¬ÕâÒâζ×ÅÎÒÃÇ¿ÉÒÔͨ¹ýÕâÁ½¸ö×Ö¶ÎÀ´¸ü¿ìµØÅÌÎÊÏà¹ØµÄÊý¾Ý¡£
ʹÓÃmigration-modules Composer°ü¾ÙÐÐË÷ÒýÉèÖÃ
³ýÁËʹÓÃLaravel¿ò¼ÜÔÉúµÄÒªÁì¾ÙÐÐË÷ÒýÉèÖã¬ÎÒÃÇÒ²¿ÉÒÔʹÓõÚÈý·½µÄComposer°üÀ´¾ÙÐÐÏàËƵIJÙ×÷¡£ÆäÖÐÒ»¸ö½ÏÁ¿ºÃµÄComposer°ü¾ÍÊÇmigration-modules¡£
ÔÚʹÓøÃComposer°ü֮ǰ£¬ÎÒÃÇÐèÒªÏÈÖ´ÐÐÒÔϵÄÓï¾ä¾ÙÐÐ×°Öãº
composer require webpress/migrations
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÎÒÃÇÐèҪʹÓÃÒÔϵÄÏÂÁîÀ´ÌìÉúÏìÓ¦µÄǨáãÎļþ£º
php artisan migrations:generate --indexes example
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöµÄÓï¾äÖУ¬example´ú±íÎÒÃÇÐèҪΪÃûΪexampleµÄ±íÉèÖÃË÷Òý¡£ÔËÐÐÕâÌõÏÂÁîºó£¬migration-modules»á×Ô¶¯½¨ÉèÏìÓ¦µÄǨáãÎļþ£¬ÎļþÖлá×Ô¶¯ÎªÎÒÃÇÉèÖÃÏìÓ¦µÄË÷Òý¡£
Èý¡¢ÔõÑùÓÅ»¯Ë÷ÒýЧÂÊ
ËäÈ»Ë÷Òý¿ÉÒÔÌá¸ßÊý¾Ý¿âÅÌÎʵÄËÙÂÊ£¬µ«²»Êʵ±µÄË÷ÒýÉèÖÃÒ²»á¶ÔÅÌÎÊÐÔÄÜÔì³É²»Á¼Ó°Ïì¡£Òò´Ë£¬ÎÒÃÇÐèÒªºÏÀíµØÉèÖÃË÷Òý£¬ÒÔÌá¸ßÅÌÎÊЧÂʺÍÓÅ»¯ÐÔÄÜ¡£
ÒÔÏÂÊǼ¸¸ö³£¼ûµÄÓÅ»¯Ë÷ÒýЧÂʵÄÒªÁ죺
×èֹʹÓùý¶àµÄË÷Òý
ËäÈ»Ë÷Òý¿ÉÒÔÌá¸ßÅÌÎÊЧÂÊ£¬µ«ÈôÊÇÉèÖùý¶àµÄË÷Òý½«»áʹÅÌÎʱäµÃÔ½·¢»ºÂý£¬ÓÉÓÚÿ¸öË÷Òý¶¼ÐèÒªÕ¼ÓÃÒ»¶¨µÄ¿Õ¼ä²¢ÇÒÐèÒª¸üС£Òò´Ë£¬ÎÒÃÇÐèÒª×èֹʹÓùý¶àµÄË÷Òý£¬Ö»Ñ¡ÔñÐëÒªµÄ×Ö¶Î×÷ΪË÷Òý£¬ÒÔÌá¸ßÅÌÎÊЧÂÊ¡£
ʹÓÃÖ¸¶¨ÀàÐ͵ÄË÷Òý
ÔÚMySQLÊý¾Ý¿âÖУ¬Ë÷ÒýÓвî±ðµÄÀàÐÍ£¬ÈçB-Tree¡¢HASHºÍFULLTEXTµÈ¡£B-TreeÊÇMySQLĬÈϵÄË÷ÒýËã·¨£¬Ò²ÊÇʹÓÃ×îÆÕ±éµÄÒ»ÖÖËã·¨¡£µ«µ±ÐèÒª¶ÔÎı¾¾ÙÐÐÈ«ÎÄËÑË÷ʱ£¬ÎÒÃÇÐèҪʹÓÃFULLTEXTÀàÐ͵ÄË÷Òý¡£
ÔöÌíÅþÁ¬ÅÌÎÊÖÐË÷ÒýµÄЧÂÊ
ÔÚÁ¬±íÅÌÎʵÄÇéÐÎÏ£¬ÎªÁËÌá¸ßÅÌÎÊЧÂÊ£¬ÎÒÃÇÐèÒªÔÚÅþÁ¬Ìõ¼þµÄ×Ö¶ÎÉϽ¨ÉèË÷Òý¡£Õâ¿ÉÒÔïÔÌJOIN²Ù×÷µÄ´ÎÊý£¬´Ó¶øÌá¸ßÅÌÎÊЧÂÊ¡£
ËÄ¡¢×ܽá
ÉèÖÃË÷ÒýÊÇÒ»¸ö»ù´¡²¢ÇÒÊ®·ÖÖ÷ÒªµÄʹÃü£¬Ëü¿ÉÒÔÌá¸ßMySQLÊý¾Ý¿âµÄÅÌÎÊЧÂʺÍÐÔÄÜ¡£ÔÚLaravel¿ò¼ÜÏ£¬ÎÒÃÇ¿ÉÒÔʹÓÃǨáãÎļþºÍµÚÈý·½Composer°üÀ´¾ÙÐÐË÷ÒýµÄÉèÖᣲ»¹ý£¬ÈôÊDz»¶ÔÀíµÄÉèÖÃË÷Òý£¬·´¶ø»áµ¼ÖÂÐÔÄÜÎÊÌâ¡£Òò´Ë£¬ÎÒÃÇÐèÒª×ñÕÕºÏÊʵÄË÷ÒýÉèÖÃÔÔòÀ´ÓÅ»¯Ë÷ÒýЧÂÊ¡£
ÒÔÉϾÍÊÇlaravelÉèÖÃË÷ÒýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡