ÔõÑùÈëÃŴLaravel¿ò¼Ü£¨½Ì³Ì£©
Ëæ×Å»¥ÁªÍøµÄÉú³¤£¬web¿ª·¢µÄÐèÇóÈÕÒæÔöÌí¡£ÔÚweb¿ª·¢ÁìÓò£¬phpÓïÑÔÒ»Ö±ÊÎÑÝ×ÅÖ÷ÒªµÄ½ÇÉ«£¬¶ølaravel¾ÍÊÇphpÓïÑÔÏÂÒ»¸ö±¸ÊܽӴýµÄweb¿ª·¢¿ò¼Ü¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÈëÃŴlaravel¿ò¼Ü¡£
Ò»¡¢LaravelÏÈÈÝ
LaravelÊÇÒ»¸ö¿ªÔ´µÄPHP Web¿ò¼Ü£¬ÓÉTaylor OtwellÔÚ2011Ä꽨Éè¡£Laravel¿ò¼ÜÊÇ»ùÓÚMVCģʽ¹¹½¨µÄ£¬ËüÌṩÁËһϵÁÐÎÞаµÄ¹¤¾ßºÍ×é¼þ£¬Äܹ»×ÊÖú¿ª·¢Õ߸ü¿ì¸üºÃµØ¹¹½¨WebÓ¦ÓóÌÐò¡£Laravel¿ò¼ÜµÄÒ»¸öÖ÷ÒªÌصãÊÇËüÇ¿µ÷¿ª·¢ÕßÓѺú;«Á·ÓÅÃÀµÄ´úÂëÆø¸Å¡£
LaravelµÄÓŵ㣺
1.ÍêÉƵÄMVC: Laravel¿ò¼ÜÇ¿ÖÆʹÓÃMVC(Model-View-Controller)Éè¼Æģʽ£¬ÓÅ»¯ÁË´úÂë½á¹¹£¬Ê¹µÃÓ¦ÓÃÔ½·¢Ò×ÓÚά»¤;
2.ArtisanÏÂÁîÐй¤¾ß: Laravel¿ò¼ÜÌṩÁËÒ»¸öÇ¿Ê¢µÄÏÂÁîÐй¤¾ßArtisan£¬¿ÉÒÔÇáËɵØÌìÉú´úÂë¡¢Êý¾ÝǨá㡢ʹÃüµ÷ÀíµÈ£»
3.×Ô´øORM: Laravel×Ô´øORM(Eloquent)£¬¿ÉÒԺܺõľÙÐÐÊý¾Ý¿â²Ù×÷£»
4.×Ô´øÄ£°åÒýÇæ: Laravel¿ò¼ÜÄÚÖÃÁËBladeÄ£°åÒýÇ棬¿ÉÒÔÔ½·¢Àû±ãµØ±àдģ°å£»
5.Çå¾²ÐԸߣºLaravel¿ò¼ÜÄÚÖÃÁËÇå¾²ÐÔ£¬°üÀ¨¿çÕ¾¾ç±¾¡¢¿çÕ¾ÇëÇóαÔìºÍSQL×¢ÈëµÈ£¬²¢ÇÒʹÓÃÁËBcrypt¼ÓÃÜËã·¨¡£
¶þ¡¢´î½¨LaravelÇéÐÎ
1.×°ÖÃXAMPPÇéÐÎ
XAMPPÊÇÒ»¸öÃâ·ÑµÄ¡¢¿ªÔ´µÄ¡¢¿çƽ̨µÄWebЧÀÍÆ÷Èí¼þ°ü£¬Ëü°üÀ¨Apache¡¢MySQL¡¢PHPºÍPerl¡£ÔÚXAMPPµÄÇéÐÎÏ£¬ÎÒÃÇ¿ÉÒԴLaravel¿ò¼Ü¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒª´ÓXAMPP¹ÙÍøÉÏÏÂÔØ×îа汾µÄXAMPP¡£×°ÖÃÀú³ÌÖУ¬ÎÒÃÇÖ»ÐèÒªµã»÷¡°ÏÂÒ»²½¡±¼´¿É£¬×°ÖÃÍê³Éºó£¬·¿ªXAMPPµÄ¿ØÖÆÃæ°å£¬Æô¶¯ApacheºÍMySQLЧÀÍ£¬È·±£ËüÃǶ¼´¦ÓÚÔËÐÐ״̬¡£
2.×°ÖÃComposer
ComposerÊÇPHPµÄÒ»ÖÖÒÀÀµÖÎÀí¹¤¾ß£¬Laravel¿ò¼Ü¾ÍÊÇʹÓÃComposer¾ÙÐÐÖÎÀíµÄ¡£ÎÒÃÇÐèÒªÏÂÔز¢×°ÖÃ×îа汾µÄComposer¡£
ÏÂÔØ×°ÖÃÍê±Ïºó£¬·¿ªÏÂÁîÐй¤¾ß£¬ÊäÈë¡°composer -V¡±£¬È·ÈÏcomposerÒѾÀÖ³É×°Öá£
3.½¨ÉèLaravelÏîÄ¿
·¿ªÏÂÁîÐй¤¾ß£¬ÊäÈëÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸öеÄLaravelÏîÄ¿£º
composer create-project --prefer-dist laravel/laravel blog
µÇ¼ºó¸´ÖÆ
ÕâÀィÉèÁËÒ»¸öÃûΪ¡°blog¡±µÄLaravelÏîÄ¿£¬–prefer-distÒâζ×Åͨ¹ýComposer´ÓLaravelµÄGithub´úÂë¿âÖÐÏÂÔØÏîÄ¿Ô´´úÂ룬²¢½¨Éè¸ÃÏîÄ¿¡£
×°ÖÃÍê±Ïºó£¬ÎÒÃÇ¿ÉÒÔ½øÈëblogĿ¼£¬ÊäÈë¡°php artisan serve¡±À´Æô¶¯LaravelµÄWebЧÀÍÆ÷£¬È»ºóÔÚä¯ÀÀÆ÷ÖÐÊäÈë¡°http://localhost:8000/¡±»á¼û×ðÁú¿Ê±LaravelÏîÄ¿¡£
Èý¡¢LaravelÏîÄ¿½á¹¹
ÔÚLaravelÏîÄ¿ÖУ¬Óм¸¸öºÜÊÇÖ÷ÒªµÄĿ¼£º
1.appĿ¼£ºÕâ¸öĿ¼ÊÇ´æ·ÅÓ¦ÓóÌÐòµÄÂß¼²ã´úÂëµÄµØ·½£¬°üÀ¨ÎÒÃÇÓ¦ÓõÄModel¡¢ViewºÍControllerµÈ;
2.bootstrapĿ¼£ºÕâ¸öĿ¼°üÀ¨ÁË¿ò¼ÜµÄÉèÖúͿò¼ÜÖ¸µ¼´úÂë;
3.configĿ¼£ºÕâÀï´æ·ÅÁËÎÒÃÇÓ¦ÓóÌÐòµÄËùÓÐÉèÖÃÎļþ£¬°üÀ¨ÁË×ðÁú¿Ê±Êý¾Ý¿âÉèÖᢻỰÉèÖá¢ÓʼþЧÀÍÌṩÕßµÈ;
4.databaseĿ¼£ºÕâ¸öĿ¼°üÀ¨ÁËÎÒÃÇÓ¦ÓóÌÐòµÄÊý¾ÝǨáãºÍÊý¾ÝÌî³äµÄ¾ç±¾;
5.publicĿ¼£ºÕâ¸öĿ¼´æ·ÅµÄÊÇÎÒÃÇÓ¦ÓóÌÐòµÄÈë¿Úindex.phpºÍÓ빫¹²×ÊÔ´ÓйصÄÎļþ£¬ÈçͼÏñ¡¢JavaScriptºÍCSSµÈ;
6.resourcesĿ¼£ºÕâÀï´æ·ÅÁËÓ¦ÓóÌÐòµÄËùÓÐÊÓͼÎļþ;
7.routesĿ¼£ºÕâ¸öĿ¼°üÀ¨ÁËÎÒÃÇÓ¦ÓóÌÐòµÄËùÓзÓÉ£¬ËùÓеÄHTTPÇëÇó¶¼ÓÉ·ÓÉ´¦Öóͷ££»
8.storageĿ¼£ºÕâ¸öĿ¼°üÀ¨storage/logs¡¢storage/app/publicºÍstorage/frameworkµÈ¶à¸ö×ÓĿ¼£¬ÕâЩĿ¼Öд洢ÁËÓ¦ÓóÌÐòµÄËùÓÐÎļþ;
9.testsĿ¼£ºÕâ¸öĿ¼°üÀ¨ÁËÎÒÃÇÓ¦ÓóÌÐòµÄËùÓвâÊÔÓÃÀý¡£
ËÄ¡¢LaravelµÄ·Óɽç˵
ÔÚLaravelÖУ¬Â·ÓÉÊÇͨ¹ý½ç˵ÔÚroutes/web.php»òroutes/api.phpÎļþÖеÄ·ÓÉÆ÷À´ÊµÏֵġ£Laravel¿ò¼ÜÌṩÁËÐí¶à¹³×Ó£¬¿ÉÒÔ½«ÇëÇó·Óɵ½Ö¸¶¨µÄ¿ØÖÆÆ÷ÒªÁìÀ´Íê³ÉÏìÓ¦µÄÂß¼¡£
Laravel·ÓÉÓï·¨£º
Route::[get|post|put|delete] (¡¯URI¡¯, ¡®¿ØÖÆÆ÷¶ÔÓ¦µÄº¯ÊýÃû¡¯);
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
Route::get('article/{id}', 'ArticleController@show');
µÇ¼ºó¸´ÖÆ
Õâ¶Î´úÂëÌåÏÖµ±ÎÒÃÇͨ¹ýGETÒªÁìÇëÇóarticle/1µÄʱ¼ä£¬½«Å²ÓÃArticleControllerµÄshowÒªÁì²¢ÏòÆäÌṩ1×÷Ϊ²ÎÊý¡£
Îå¡¢½áÓï
±¾ÎÄÏÈÈÝÁËLaravel¿ò¼ÜÈëÃŴ¡£Laravel¿ò¼Ü¾ßÓкܺõÄϵͳ½á¹¹£¬¿ÉÒÔ×ÊÖú¿ª·¢Õ߸ü¿ì¸üºÃµØ¹¹½¨WebÓ¦ÓóÌÐò¡£Ï£Íû¶ÁÕßͨ¹ý±¾ÎÄÄܹ»¶ÔLaravel¿ò¼ÜÓÐÒ»¶¨µÄÏàʶ£¬Î´À´Äܹ»ÇáËɴ×Ô¼ºµÄWebÓ¦ÓóÌÐò¡£
ÒÔÉϾÍÊÇÔõÑùÈëÃŴLaravel¿ò¼Ü£¨½Ì³Ì£©µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡