laravelÕÒ²»µ½Ñùʽ
ÔÚ¿ª·¢webÓ¦ÓóÌÐòʱ£¬Ê¹ÓÃһЩǰ¶Ë¿ò¼ÜºÍ¿âÊǺܳ£¼ûµÄÊÂÇé¡£laravel×÷ΪһÖÖÊ¢ÐеÄphp web¿ò¼Ü£¬¿ÉÒÔ¼¯³ÉÖÖÖÖÇ°¶Ë¿ò¼ÜºÍ¿â¡£¿ÉÊÇÓÐʱ¼äÄã»á·¢Ã÷ÄãµÄlaravelÏîÄ¿ÖмÓÔز»³öÔ¤ÆÚµÄÑùʽ£¬Õâʱ¼ä¾ÍÐèÒªÕÒ³öÎÊÌâ³öÔÚÄÇÀ½â¾öÎÊÌâ¡£
Ê×ÏÈ£¬ÄãÐèҪȷ¶¨ÄãµÄÑùʽÎļþÊÇ·ñ±£´æ¡£ÔÚLaravel ÏîÄ¿ÖУ¬Ò»Ñùƽ³£ÇéÐÎÏÂCSSºÍJSÎļþÊÇ´æ·ÅÔÚpublicĿ¼Ïµģ¬Äã¿ÉÒÔͨ¹ýÔÚä¯ÀÀÆ÷µØµãÀ¸ÖÐÊäÈëhttp://localhost:8000/css/your_css_file.cssÉó²éÄãµÄÑùʽÎļþÊÇ·ñ±£´æ¡£ÈôÊÇÎļþ²»±£´æ£¬ËµÃ÷LaravelÔÚÆô¶¯ÏîĿʱûÓÐ׼ȷµØÌìÉúËüÃÇ¡£
Laravel ÏîÄ¿Æô¶¯Ê±»áÖ´ÐÐÐí¶à²Ù×÷¡£ÆäÖÐÒ»¸ö²Ù×÷ÊÇŲÓÃartisan serveÏÂÁ¸ÃÏÂÁî»áÆô¶¯Ò»¸öЧÀÍ£¬ÓÃÓÚ½«Ó¦ÓóÌÐòÊä³öµ½ä¯ÀÀÆ÷ÖС£Í¨³££¬ÈôÊÇÑùʽÎļþɥʧ£¬Ôµ¹ÊÔÓÉ¿ÉÄÜÊÇÔËÐÐÏÂÁîʱ²ÎÊýת´ïʧ°Ü»òĿ¼ȨÏÞȱ·¦µÈÎÊÌâ¡£
µ±ÄãʹÓÃLaravel MixÒÔ¼°ÆäËûÇ°¶Ë¹¹½¨¹¤¾ßʱ£¬ÄãÐèÒªÌìÉúCSSºÍJSÎļþ¡£Laravel Mix»á½«Ô´´úÂë±àÒë³Éä¯ÀÀÆ÷¿ÉÒÔÃ÷È·µÄ´úÂ룬²¢½«Æä´æ´¢ÔÚpublicÎļþ¼ÐÖС£ÈôÊÇÄãÏëÒªÔÚLaravelÏîÄ¿ÖÐÒýÓÃÕâЩÎļþ£¬ÄãÐèҪȷ±£ËüÃÇ´æ´¢ÔÚ׼ȷµÄ·¾¶Ï¡£ÕâÊÇÓÉÓÚLaravel²¢²»ÖªµÀÄÄЩÎļþÓ¦¸ÃÓÃÓÚÇ°¶ËäÖȾ¡£
ÈôÊÇÄãµÄLaravelÏîÄ¿ÖеÄCSSºÍJSÎļþ±£´æ£¬ÄÇô½ÓÏÂÀ´ÐèÒª¼ì²éÊÇ·ñ׼ȷÒýÓÃÁËÑùʽÎļþ¡£¿ÉÄÜ·ºÆðÒ»¸ö³£¼ûÎÊÌâÊÇ£¬µ±ÄãÔÚÎļþÖÐʹÓÃasset()º¯ÊýÒýÓÃCSSºÍJSÎļþʱ£¬ËüÎÞ·¨×¼È·µØÆÊÎöÎļþ·¾¶¡£Õâ¸öÎÊÌâÔÚʹÓÃLaravelµÄ¹²ÏíÖ÷»úÍйÜʱÌØÊâÈÝÒ×±¬·¢¡£
ΪÏàʶ¾öÕâ¸öÎÊÌ⣬Äã¿ÉÒÔʹÓÃurl()º¯Êý¶ø²»ÊÇasset()º¯Êý¡£ÕâÊÇÓÉÓÚurl()º¯ÊýÌìÉúµÄURL×ÜÊÇÏà¹ØÓÚÄãµÄÏîÄ¿¸ùĿ¼¡£ÔÚʹÓÃurl()º¯Êýʱ£¬ÄãÐèҪȷ±£ÄãµÄÇëÇóURLÖÐÓÐÇ°µ¼Ð±¸Ë¡£Äã¿ÉÒÔÔÚÊÓͼÎļþÖÐʹÓÃÒÔÏ´úÂ룺
<link href="{{ url('/css/your_css_file.css') }}" rel="stylesheet"> <script src="{{ url('/js/your_js_file.js') }}"></script>
µÇ¼ºó¸´ÖÆ
ÈôÊÇÄãÔÚЧÀÍÆ÷ÉÏÔËÐÐPHPʱʹÓÃÁËPHP-FPM£¬»òÕßʹÓÃÁËHTTPЧÀÍÆ÷¾ÙÐз´ÏòÊðÀí£¬ÄÇôÄãÐèÒªÌí¼ÓһЩÌØÁíÍâÉèÖá£ÔÚNginxÖÐÌí¼ÓÒÔÏÂÉèÖãº
location / { try_files $uri $uri/ /index.php?$query_string; }
µÇ¼ºó¸´ÖÆ
ÕâÑù£¬ÈôÊÇÄãµÄÑùʽÎļþÎÞ·¨±»ÕÒµ½£¬Laravel»á½«ÇëÇóת·¢µ½index.phpÎļþÖУ¬´Ó¶ø°ü¹ÜÇëÇóÄܹ»±»´¦Àí¡£
ÈôÊÇÄãµÄÑùʽÎļþ·¾¶×¼È·£¬¿ÉÊÇÕÕ¾ÉÎÞ·¨×¼È·µØ¼ÓÔØ£¬ÄÇ¿ÉÄÜÊÇ»º´æµÄÎÊÌâ¡£Äã¿ÉÒÔɨ³ýä¯ÀÀÆ÷»º´æ²¢ÖØмÓÔØÒ³Ã棬Ȼºó¿´¿´ÎÊÌâÊÇ·ñ»ñµÃ½â¾ö¡£ÈôÊÇÕÕ¾ÉûÓнâ¾ö£¬Äã¿ÉÒÔÔËÐÐÒÔÏÂÏÂÁîɨ³ýLaravelµÄ»º´æÎļþ£º
php artisan cache:clear php artisan config:cache php artisan route:cache
µÇ¼ºó¸´ÖÆ
ÕâЩÏÂÁɨ³ýLaravelµÄ»º´æÎļþ£¬²¢ÖØÐÂÌìÉúËüÃÇ¡£ÔÚÖ´ÐÐÕâЩÏÂÁîÖ®ºó£¬ÄãÐèÒªÖØÐÂÆô¶¯LaravelЧÀÍ£¬ÒÔ±ãËüÖØмÓÔØ»º´æÎļþ¡£
×ÜÖ®£¬ÈôÊÇÄãµÄLaravelÏîÄ¿ÖÐÎÞ·¨¼ÓÔØÑùʽÎļþ£¬ÄÇôÄãÐèÒª¼ì²éÑùʽÎļþÊÇ·ñ±£´æ¡¢ÑùʽÎļþ·¾¶ÊÇ·ñ׼ȷ¡¢ÒýÓÃÑùʽÎļþµÄ´úÂëÊÇ·ñ׼ȷÒÔ¼°»º´æÊÇ·ñ±»É¨³ýµÈÎÊÌâ¡£ÔÚ½â¾öÕâЩÎÊÌâºó£¬ÄãµÄLaravelÏîÄ¿¾ÍÄÜ׼ȷµØ¼ÓÔØÑùʽÎļþÁË¡£
ÒÔÉϾÍÊÇlaravelÕÒ²»µ½ÑùʽµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡