×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravel ÅжÏÇëÇóÒ³Ãæ

laravel×÷Ϊһ¿îÊ¢ÐеÄphp¿ò¼Ü£¬Æä×î´óµÄÌصãÊÇÆäÎÞаÐÔºÍÒ×ÓÃÐÔ¡£ÔÚ¿ª·¢Àú³ÌÖУ¬ÔõÑùÅжÏÇëÇóµÄÒ³ÃæÊÇÎÒÃÇÐèÒªÒ»Ö±¹Ø×¢µÄ»°Ìâ¡£±¾ÎĽ«Õë¶ÔlaravelÖÐÅжÏÇëÇóÒ³ÃæµÄÏà¹ØÒªÁì×öÒ»¸ö¼òÆÓµÄÏÈÈÝ¡£

Ò»¡¢ÅжÏÇëÇóµÄÒªÁì

1.1¡¢Ê¹ÓÃRequestÀàµÄisMethodÒªÁì

LaravelµÄRequestÀàµÄisMethodÒªÁì¿ÉÓÃÓÚÅжÏÇëÇóµÄÒªÁì¡£ÀýÈ磺

use IlluminateHttpRequest;

Route::post('/submit', function (Request $request) {
    if ($request->isMethod('post')) {
        //Ìá½»±íµ¥
    }
});

µÇ¼ºó¸´ÖÆ

1.2¡¢Ê¹ÓÃRequestÀàµÄÒªÁìÃû

³ýÁËisMethodÒªÁ죬»¹¿ÉÒÔʹÓÃRequestÀàµÄ¶ÔÓ¦ÒªÁìÃû¾ÙÐÐÅжÏ£¬ÀýÈ磺

use IlluminateHttpRequest;

Route::post('/submit', function (Request $request) {
    if ($request->isPost()) {
        //Ìá½»±íµ¥
    }
});

µÇ¼ºó¸´ÖÆ

×¢ÖØ£º¹ØÓÚPUT¡¢PATCHºÍDELETEÇëÇó£¬Ê¹ÓÃÉÏÊöÒªÁìʱÐèÒªÔÚ±íµ¥ÖмÓÈë_method×ֶΣ¬ÏêϸҪÁì¿É²Î¿¼Laravel¹Ù·½Îĵµ¡£

¶þ¡¢ÅжÏÇëÇóµÄ·ÓÉ

2.1¡¢Ê¹ÓÃRequestÀàµÄrouteIsÒªÁì

LaravelµÄRequestÀàµÄrouteIsÒªÁì¿ÉÒÔÓÃÓÚÅжÏÄ¿½ñ·ÓÉÊÇ·ñÓëÖ¸¶¨µÄ·ÓÉÃûÆ¥Å䣬ÀýÈ磺

use IlluminateHttpRequest;

Route::get('/page', function (Request $request) {
    if ($request->routeIs('page')) {
        //Ö´ÐÐÏà¹Ø²Ù×÷
    }
})->name('page');

µÇ¼ºó¸´ÖÆ

2.2¡¢Ê¹ÓÃRouteÀàµÄcurrentRouteNameÒªÁì

LaravelµÄRouteÀàµÄcurrentRouteNameÒªÁì¿ÉÒÔÓÃÓÚ»ñÈ¡Ä¿½ñ·ÓɵÄÃû³Æ£¬ÀýÈ磺

use IlluminateSupportFacadesRoute;

Route::get('/page', function () {
    $currentRouteName = Route::currentRouteName();
    if ($currentRouteName == 'page') {
        //Ö´ÐÐÏà¹Ø²Ù×÷
    }
})->name('page');

µÇ¼ºó¸´ÖÆ

Èý¡¢ÅжÏÇëÇóµÄURL

3.1¡¢Ê¹ÓÃRequestÀàµÄisÒªÁì

LaravelµÄRequestÀàµÄisÒªÁì¿ÉÒÔÓÃÓÚÅжÏÄ¿½ñURLÊÇ·ñÆ¥ÅäÖ¸¶¨µÄURL£¬ÀýÈ磺

use IlluminateHttpRequest;

Route::get('/page', function (Request $request) {
    if ($request->is('/page')) {
        //Ö´ÐÐÏà¹Ø²Ù×÷
    }
});

µÇ¼ºó¸´ÖÆ

3.2¡¢Ê¹ÓÃRequestÀàµÄfullUrlIsÒªÁì

LaravelµÄRequestÀàµÄfullUrlIsÒªÁì¿ÉÒÔÓÃÓÚÅжÏÄ¿½ñÍêÕûµÄURLÊÇ·ñÆ¥ÅäÖ¸¶¨µÄURL£¬ÀýÈ磺

use IlluminateHttpRequest;

Route::get('/page', function (Request $request) {
    if ($request->fullUrlIs('http://localhost/page')) {
        //Ö´ÐÐÏà¹Ø²Ù×÷
    }
});

µÇ¼ºó¸´ÖÆ

ËÄ¡¢×ܽá

±¾ÎļòÆÓÏÈÈÝÁËLaravelÖÐÅжÏÇëÇóÒ³ÃæµÄÏà¹ØÒªÁ죬°üÀ¨ÅжÏÇëÇóµÄÒªÁì¡¢ÅжÏÇëÇóµÄ·ÓɺÍÅжÏÇëÇóµÄURL¡£ÔÚÏÖʵ¿ª·¢Àú³ÌÖУ¬ÎÒÃÇ¿ÉÒÔƾ֤ÐèҪѡÔñ²î±ðµÄÒªÁì¾ÙÐÐÅжÏ£¬ÒÔʵÏÖÔ½·¢ÎÞаºÍ׼ȷµÄ¿ØÖÆ¡£

ÒÔÉϾÍÊÇlaravel ÅжÏÇëÇóÒ³ÃæµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ