laravel·ÓÉÌøתʧ°Ü
ÔÚʹÓà laravel ¿ò¼Ü¾ÙÐпª·¢µÄÀú³ÌÖУ¬ÎÒÃǾ³£ÐèҪʹÓõ½Â·ÓÉÌøת£¬¿ÉÊÇÔÚijЩÇéÐÎÏ£¬ÎÒÃÇ¿ÉÄÜ»áÓöµ½Â·ÓÉÌøתʧ°ÜµÄÇéÐΣ¬µ¼ÖÂÎÒÃǵÄÓ¦ÓÃÎÞ·¨Õý³£ÔËÐС£±¾ÎĽ«ÏÈÈÝһЩ³£¼ûµÄ laravel ·ÓÉÌøתʧ°ÜµÄÔµ¹ÊÔÓÉÒÔ¼°½â¾öÒªÁì¡£
·ÓÉÌøתµÄ·¾¶²»×¼È·
ÈôÊÇÎÒÃÇÔÚʹÓà Laravel ¾ÙÐзÓÉÌøתʱ£¬Â·¾¶²»×¼È·£¬ÊÇÎÞ·¨ÀÖ³ÉÌøתµÄ¡£Òò´Ë£¬Ê×ÏÈÐèҪȷ±£ÎÒÃÇдµÄÌøת·¾¶×¼È·¡£ÎÒÃÇ¿ÉÒÔʵÑéʹÓÃÏÂÁîÐÐÊäÈë php artisan route:list À´Éó²éÎÒÃǽç˵µÄ·ÓÉÁÐ±í¼°Æä¶ÔÓ¦µÄ·¾¶£¬È·±£Ìøת·¾¶µÄ׼ȷÐÔ¡£
Öض¨Ïò»á»°ÓâÆÚ
ÔÚ Laravel Ó¦ÓÃÖУ¬Öض¨Ïòµ½ÁíÒ»¸ö·ÓÉʱ£¬Ó¦ÓûὫĿ½ñ»á»°ÐÅÏ¢´æ´¢µ½»á»°ÖÐÐļþÖС£µ±Â·ÓÉÌøתʧ°Üʱ£¬»á»°ÐÅÏ¢»áÓâÆÚ²¢±»Ïú»Ù¡£ÎªÁË×èÖ¹»á»°ÐÅÏ¢ÓâÆÚ£¬ÎÒÃÇ¿ÉÒÔʹÓà Laravel ÌṩµÄ Redirect ÀàÖÐÐļþ£¬½«Öض¨ÏòÇëÇó·¢Ë͵½ÁíÒ»¸öURL£¬²¢´øÊÜÆÇ°»á»°ÐÅÏ¢¡£ÀýÈ磺
return redirect()->route('home')->with('message', 'Welcome back!');
µÇ¼ºó¸´ÖÆ
ÎÞ·¨ÕÒµ½¿ØÖÆÆ÷
µ±ÎÒÃǽç˵һ¸ö·ÓÉʱ£¬ÎÒÃÇÐèÒªÖ¸¶¨¶ÔÓ¦µÄ¿ØÖÆÆ÷¼°ÆäÒªÁì¡£ÈôÊÇÎÒÃÇÔÚÖ¸¶¨¿ØÖÆÆ÷ʱ£¬Â·¾¶²»×¼È·»òÕß¿ØÖÆÆ÷Ãû³Æ²»×¼È·£¬Ôò»áÌøתʧ°Ü¡£ÔÚ Laravel Ó¦ÓÃÖУ¬ÎÒÃÇÐèÒª½«¿ØÖÆÆ÷°²ÅÅÔÚ app/Http/Controllers Ŀ¼Ï£¬²¢Ê¹ÓÃÃüÃû¿Õ¼ä AppHttpControllers¡£ÀýÈ磬ÎÒÃǽç˵һ¸öÃûΪ HomeController µÄ¿ØÖÆÆ÷£¬ËüµÄ·¾¶Ó¦¸ÃΪ app/Http/Controllers/HomeController.php£¬²¢ÇÒËüµÄÃüÃû¿Õ¼äÓ¦¸ÃΪ AppHttpControllers¡£ÔÚ½ç˵·ÓÉʱ£¬ÎÒÃÇÐèҪͨ¹ý¿ØÖÆÆ÷Ãû³ÆºÍÒªÁìÃû³ÆÀ´Ö¸¶¨Â·ÓɶÔÓ¦µÄ²Ù×÷¡£ÀýÈ磺
Route::get('/home', 'HomeController@index')->name('home');
µÇ¼ºó¸´ÖÆ
ʹÓùýʧµÄ HTTP ÒªÁì
ÔÚ Laravel Ó¦ÓÃÖУ¬²î±ðµÄ HTTP ÒªÁì¶ÔÓ¦²î±ðµÄ·ÓɺͶÔÓ¦µÄ²Ù×÷¡£ÀýÈç GET ÇëÇóÒ»Ñùƽ³£ÌåÏÖÅÌÎÊ×ÊÔ´£¬POST ÇëÇóÒ»Ñùƽ³£ÓÃÓÚ½¨Éè×ÊÔ´µÈ¡£ÈôÊÇÎÒÃÇÔÚ½ç˵·ÓÉʱ£¬Ê¹ÓÃÁ˹ýʧµÄ HTTP ÒªÁ죬»áµ¼Ö·ÓÉÌøתʧ°Ü¡£ÔÚ Laravel ÖУ¬ÎÒÃÇ¿ÉÒÔʹÓà Route ÀàµÄ²î±ðÒªÁìÀ´½ç˵²î±ð HTTP ÒªÁìµÄ·ÓÉ¡£ÀýÈ磺
Route::get('/users', 'UserController@index')->name('users.index'); Route::post('/users', 'UserController@store')->name('users.store');
µÇ¼ºó¸´ÖÆ
·ÓÉÃüÃû³åÍ»
µ±ÎÒÃǽç˵¶à¸ö·ÓÉʱ£¬ÈôÊÇ·ÓɵÄÃû³ÆÏàͬ£¬»áµ¼ÖÂÃüÃû³åÍ»£¬´Ó¶øÎÞ·¨ÀÖ³ÉÌøת¡£ÎªÁË×èÖ¹ÃüÃû³åÍ»£¬ÎÒÃÇÐèÒªÔÚ½ç˵·ÓÉʱΪÿ¸ö·ÓÉÖ¸¶¨²î±ðµÄÃû³Æ¡£ÀýÈ磺
Route::get('/home', 'HomeController@index')->name('home'); Route::get('/about', 'AboutController@index')->name('about');
µÇ¼ºó¸´ÖÆ
ÔÚ Laravel Ó¦ÓÃÖУ¬Â·ÓÉÌøתʧ°Ü¿ÉÄÜÓÉÐí¶àÔµ¹ÊÔÓÉÒýÆð¡£ÎÒÃÇÐèÒª×Ðϸ¼ì²é·ÓÉ·¾¶µÄ׼ȷÐÔ¡¢¿ØÖÆÆ÷Ãû³ÆºÍÒªÁì¡¢HTTP ÒªÁì¡¢ÃüÃû³åÍ»µÈÎÊÌâ¡£ÈôÊÇÎÒÃÇ·ºÆðÁËÎÊÌ⣬ÎÒÃÇ¿ÉÒÔͨ¹ý Laravel ÌṩµÄ¹ýʧÌáÐÑÀ´ÕÒ³öÎÊÌâËùÔÚ²¢¼ÓÒÔ½â¾ö¡£ÕâÑù£¬ÎÒÃǾÍÄܹ»Ë³ËìʹÓà Laravel ¾ÙÐзÓÉÌøתÁË¡£
ÒÔÉϾÍÊÇlaravel·ÓÉÌøתʧ°ÜµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡