laravelÕÒ²»µ½Â·ÓÉÔõô°ì
½üÄêÀ´£¬laravelÒѾ³ÉΪÁËphpÉçÇøÖÐ×îÊ¢ÐеÄmvc¿ò¼ÜÖ®Ò»£¬ËüµÄÓÅÑźͿÉÀ©Õ¹ÐÔʹÆä³ÉΪÁËÐí¶àweb¿ª·¢ÕßµÄÊ×Ñ¡¡£¿ÉÊÇ£¬laravelµÄÎĵµ²¢²»ÊÇÊ®·ÖÍêÉÆ£¬ÓÐʱÎÒÃÇÔÚ¿ª·¢Àú³ÌÖÐÕվɻáÓöµ½Ò»Ð©¹îÒìµÄÎÊÌâ¡£ÆäÖУ¬×î³£¼ûµÄÎÊÌâ¾ÍÊÇ¡°ÕÒ²»µ½Â·ÓÉ¡±¡£
LaravelµÄ·ÓÉϵͳּÔÚ½«URIÇëÇóÓ³Éäµ½´úÂëÖеÄÌض¨Ðж¯¡£Â·ÓÉ¿ÉÒÔ½ç˵ÔÚweb.phpÎļþÖУ¬Ò²¿ÉÒÔ½ç˵ÔÚapi.phpÎļþÖС£ÔÚÕâЩÎļþÖУ¬ÎÒÃÇ¿ÉÒÔ½ç˵²î±ðµÄURIºÍÇëÇóÒªÁìÖ®¼äµÄÓ³Éä¹Øϵ¡£ÎÒÃÇÒ²¿ÉÒÔΪ·ÓÉÖ¸¶¨Ò»¸ö¿ØÖÆÆ÷ÒªÁ죬È÷ÓÉÄÚµÄÇëÇóÔÚ¿ØÖÆÆ÷ÖеÃËæ´¦Àí¡£
¿ÉÊÇ£¬µ±ÎÒÃÇÔÚä¯ÀÀÆ÷Öлá¼ûÌض¨µÄ·ÓÉʱ£¬È´¿ÉÄÜ»áÓöµ½¡°404 Not Found¡±µÄ¹ýʧ¡£Õâͨ³£Òâζ×ÅLaravelÕÒ²»µ½Õâ¸ö·ÓÉ¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒÃǽ«Ì½ÌÖһЩ¿ÉÄܵ¼ÖÂLaravelÕÒ²»µ½Â·ÓɵÄÔµ¹ÊÔÓÉ£¬²¢Ìṩ½â¾ö¼Æ»®¡£
ÎÊÌâ1£ºURI¹ýʧ
Ó¦¸ÃÊ×ÏÈÈ·ÈÏURIÊÇ·ñ׼ȷ¡£ÓÐʱÎÒÃÇÊÖд·Óɲ¢ÇÒÔÚ±àдURIʱ·ºÆðÁËһЩ¹ýʧ£¬ÀýÈçƴд¹ýʧ»ò¹ýʧµÄ¾Þϸд¡£ÔÚÕâÖÖÇéÐÎÏ£¬Laravel½«ÎÞ·¨ÕÒµ½Â·Óɲ¢·µ»ØÒ»¸ö404¹ýʧ¡£ÎÒÃÇ¿ÉÒÔͨ¹ý¼ì²é·Óɱí»òʹÓ÷ÓÉÃû³ÆÀ´½â¾ö´ËÎÊÌâ¡£ÀýÈ磬ÈôÊǽç˵ÁËÒÔÏ·ÓÉ£º
Route::get('/users', 'UserController@index')->name('users.index');
µÇ¼ºó¸´ÖÆ
ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏ·½·¨ÌìÉú·ÓÉURI£º
route('users.index');
µÇ¼ºó¸´ÖÆ
Õ⽫ÌìÉú/usersµÄURI£¬¶ø²»ÐèÒªÊÖ¶¯±àдURI¡£ÕâÑù¿ÉÒÔ×èÖ¹ÓÉÓÚÊÖдURI¶øÒýÆðµÄƴд¹ýʧ¡£
ÎÊÌâ2£ºÂ·ÓÉ»º´æ
LaravelÌṩÁËÒ»¸ö¿ÉÒÔÏñcomposer.jsonÒ»Ñù»º´æ·ÓɱíµÄÏÂÁîÐй¤¾ß£¬¿ÉÒÔ¼ÓËÙÆô¶¯ËÙÂÊ¡£¿ÉÊÇ£¬ÈôÊÇÎÒÃÇÔÚweb.php»òapi.phpÎļþÖÐÌí¼Ó»ò±à¼ÁË·Óɲ¢Ê¹ÓÃÁË·ÓÉ»º´æ£¬ÕâÑùµÄ¸ü¸Ä½«²»»áÉúЧ¡£ÎÒÃÇÐèҪɨ³ý·ÓÉ»º´æ²¢ÖØÐÂÌìÉú·ÓÉ»º´æ¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîɨ³ý·ÓÉ»º´æ£º
php artisan route:clear
µÇ¼ºó¸´ÖÆ
È»ºóÖØÐÂÌìÉú·ÓÉ»º´æ£º
php artisan route:cache
µÇ¼ºó¸´ÖÆ
¿ÉÊÇ£¬ÈôÊÇÓ¦ÓóÌÐòÒÀÀµÓÚ¶¯Ì¬Â·ÓÉ»ò·ÓɲÎÊý£¬ÔòÎÞ·¨Ê¹Ó÷ÓÉ»º´æ¡£ÔÚÕâÖÖÇéÐÎÏ£¬ÎÒÃÇÖ»ÐèʹÓÃroute: clearɨ³ý»º´æ¼´¿É¡£
ÎÊÌâ3£ºÃüÃû¿Õ¼ä¹ýʧ
ÃüÃû¿Õ¼ä¹ýʧҲ¿ÉÄܵ¼ÖÂLaravelÕÒ²»µ½Â·ÓÉ¡£Õâͨ³£ÔÚÎÒÃǵĿØÖÆÆ÷λÓÚǶÌ×µÄĿ¼½á¹¹ÖÐʱ±¬·¢¡£ÎÒÃÇÐèҪȷ±£Â·ÓÉÖÐÖ¸¶¨ÁË׼ȷµÄÃüÃû¿Õ¼ä¡£ÀýÈ磬ÈôÊÇÓÐÒÔÏÂĿ¼½á¹¹£º
app/ Http/ Controllers/ Admin/ UserController.php
µÇ¼ºó¸´ÖÆ
ͬʱ£¬ÎÒÃÇÔÚ¿ØÖÆÆ÷ÖÐÖ¸¶¨ÁËÃüÃû¿Õ¼ä£º
namespace App\Http\Controllers\Admin;
µÇ¼ºó¸´ÖÆ
ÔÚ½ç˵·ÓÉʱ£¬ÎÒÃÇÐèҪʹÓÃÍêÕûµÄ¿ØÖÆÆ÷ÀàÃû»òʹÓÃasÒªÁìÀ´Ö¸¶¨¿ØÖÆÆ÷ÃüÃû¿Õ¼ä¡£ÀýÈ磺
Route::get('/users', 'App\Http\Controllers\Admin\UserController@index');
µÇ¼ºó¸´ÖÆ
»òÕßʹÓÃasÒªÁ죺
Route::namespace('Admin')->group(function () { Route::get('/users', 'UserController@index')->name('users.index'); });
µÇ¼ºó¸´ÖÆ
ÕâÑù×ö¿ÉÒÔÈ·±£ÎÒÃǵÄ·ÓÉʹÓÃÁË׼ȷµÄÃüÃû¿Õ¼ä¡£
ÎÊÌâ4£º¸üÐÂcomposerÒÀÀµ
¿ÉÄÜÎÒÃǵÄLaravel°æ±¾ÒѾ¸üУ¬¿ÉÊÇÎÒÃÇûÓиüÐÂcomposerÒÀÀµ¡£Õâ¿ÉÄܵ¼ÖÂijЩÀàÎÞ·¨¼ÓÔØ£¬´Ó¶øµ¼Ö·ÓÉÎÞ·¨ÕÒµ½¹ýʧ¡£ÎÒÃÇ¿ÉÒÔÔÚÖÕ¶ËÖÐÔËÐÐÒÔÏÂÏÂÁîÀ´¸üÐÂÒÀÀµÏ
composer update
µÇ¼ºó¸´ÖÆ
Õ⽫¸üÐÂÎÒÃǵÄÒÀÀµÏî²¢½â¾öÕÒ²»µ½Â·ÓɵÄÎÊÌâ¡£
ÎÊÌâ5£ºÉèÖùýʧ
LaravelºÍPHP×Ô¼º¶¼ÓÐÐí¶àÉèÖÃÑ¡Ïî¡£ÈôÊÇÎÒÃǵÄÉèÖÃÓÐÎó£¬Ôò¿ÉÄܵ¼ÖÂLaravelÕÒ²»µ½Â·ÓÉ¡£ÔÚÕâÖÖÇéÐÎÏ£¬ÎÒÃÇ¿ÉÒÔ¼ì²éconfigÎļþ¼ÐÖеÄÉèÖÃÎļþÊÇ·ñ׼ȷ¡£ÀýÈ磬ÈôÊÇÎÒÃǵÄSeesionÇý¶¯³ÌÐòÉèÖÃΪʹÓÃDatabase´æ´¢£¬ÔòÐèҪȷ±£×¼È·µØÉèÖÃÁËÅþÁ¬¡£ÎÒÃÇ¿ÉÒÔÔÚconfig / session.phpÎļþÖÐÕÒµ½ÒÔÏÂÉèÖãº
'driver' => 'database', // ... 'connection' => null,
µÇ¼ºó¸´ÖÆ
´ËʱӦ¸ÃÈ·±£Êý¾Ý¿âÉèÖÃÑ¡Ïî׼ȷ£¬²¢ÇÒÓë¸ÃÅþÁ¬Ãû³ÆÆ¥Åä¡£
½áÂÛ
ÔÚLaravel¿ª·¢Àú³ÌÖУ¬¿ÉÄÜ»áÓöµ½ÕÒ²»µ½Â·ÓɵĹýʧ¡£Í¨³££¬ÕâÖÖ¹ýʧÊÇÓÉÓÚURI»òÃüÃû¿Õ¼ä¹ýʧ¡¢Â·ÓÉ»º´æ¡¢composerÒÀÀµ»òÉèÖùýʧµÈÔµ¹ÊÔÓɵ¼Öµġ£Í¨¹ý¼ì²éÕâЩ³£¼ûÎÊÌⲢʹÓÃÏìÓ¦µÄ½â¾ö¼Æ»®£¬ÎÒÃÇ¿ÉÒÔÇáËɵØÐÞ¸´Â·ÓÉÎÊÌâ²¢¼ÌÐø¸ßЧµØ¿ª·¢¡£
ÒÔÉϾÍÊÇlaravelÕÒ²»µ½Â·ÓÉÔõô°ìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡