2017-12-22 2 views
0

단일 도메인/하위 도메인 프로젝트가 있습니다. 내 페이지가 제대로로드되지 않은 후, 컨트롤러에서 덤프를했다 라우트 라우팅 이상한 동작

Route::prefix('events')->namespace('Content\Controller')->group(function() { 
    Route::get('/', '[email protected]')->name('event.index'); 
    Route::get('{slug}', '[email protected]')->name('event.show'); 
    Route::get('{slug}/edit', '[email protected]')->name('event.edit'); 
    Route::post('load-more-ajax/{region?}', '[email protected]'); 
    Route::any('sorted-ajax/{region?}', '[email protected]'); 
    Route::get('category/{category_slug}/{subcategory_slug?}', '[email protected]'); 
}); 

가 :

public function getView($slug) 
{ 
    return $slug; 
} 

이 경로에 도착하는 슬러그하여 이벤트를보기 위해,이 경로를 만들어 이 URL은 https://example.com/events/slug-example입니다.

문제는 경로를 변경했을 때 응답이 표시 될 때 경로가 맞았지만 대신 슬러그가 표시되지 않는다는 것입니다. 대신 Region 개체가 반환됩니다.

내가 이렇게 할 경우 :

public function getView($region, $slug) 
{ 
    return $slug; 
} 

가 그럼 난 슬러그를 다시 얻을. 그러나 나는 이것이 어떻게 가능하고, 어떻게 할 수 있을지 전혀 모른다. (나는 기존 프로젝트에서 다른 개발자로왔다).

모든 미들웨어를 주석 처리했지만 여전히 동일합니다. 명시 적으로 말하지 않으면 무엇을 어떻게 채울 수 있습니까?

Route::bind('region', function ($value) { 
    ... 
}); 

지금 dd($value) 내가 변수를 얻을 경우 다시 :

편집

나는 루트 파일에서 진행이 구속력이났습니다. 이 값은 어떻게 채워 집니까? 어디서부터 전달 될 수 있습니까?

+0

당신이 때이 채워져'{지역}'URL을 시도하지만 당신은 당신이하지 않은 주장하고 불가능 routeso 당신은 {슬러그}''타격 이 경로에 지역이 있다는 것입니다. –

+0

나는 그렇다! 질문에 추가하는 것을 잊어 버렸습니다. 'example.com'대신 '{region} .example.com'을 치고 있습니다. 그 중 하나가 먼저 읽혀집니다. 감사합니다 – Norgul

+1

그래서 이것은 올바른 동작입니다. 지역을 매개 변수로 사용하는 경우 컨트롤러 메서드 –

답변

1

빨리 살펴보면 제대로 작동하지만 어쩌면 다른 URL을 확인하고 있습니다.

은 넣어 있는지 확인하십시오 :

Route::get('{slug}', '[email protected]')->name('event.show'); 
Route::get('{slug}/edit', '[email protected]')->name('event.edit'); 

경로를 당신이 보여 경로의 끝에서.

편집

당신이 그런 경우가 아니라 당신이 당신의 경로 당신이 실행해야 캐시가없는 생각하는 경우 :

php artisan route:list 

당신의 경로를 확인합니다. 주석의 작전에 의해 설명 후, 도메인이 사이트에 액세스하는 데 사용

EDIT2

은 다음과 같습니다

{region}.example.com 

그래서 첫번째 매개 변수로 컨트롤러 $region있는 것은 때문에 경로 모델 바인딩 및 기타의 올바른 행동입니다 경로 매개 변수는 2, 3 등이됩니다.

+0

경로가 맞았으므로 순서가 중요하지 않습니다. – Norgul

+0

'sorted-ajax' url이 이제'EventController @ getView'로 들어가기 때문에 순서가 중요합니다. 확실히 당신은'getView'에 어떤 영역도 가져서는 안됩니다. 그래서 당신이 진짜 유효한 URL을 사용하고 있고 유효한 컨트롤러 메소드에 들어가 있는지 확인해야합니다. 이전에 캐시 한 경우'php artisan route : clear'을 실행해야 할 수도 있습니다. –

+0

예,하지만 여기에 문제가되지 않습니다, 나는 올바른 길을 가고 있습니다. – Norgul

0

대신

Route::prefix('events')->namespace('Content\Controller')->group(function() { 
    Route::get('/', '[email protected]')->name('event.index'); 
    Route::get('{slug}', '[email protected]')->name('event.show'); 
    Route::get('{slug}/edit', '[email protected]')->name('event.edit'); 
    Route::post('load-more-ajax/{region?}', '[email protected]'); 
    Route::any('sorted-ajax/{region?}', '[email protected]'); 
    Route::get('category/{category_slug}/{subcategory_slug?}', '[email protected]'); 
}); 

Route::prefix('events')->namespace('Content\Controller')->group(function() { 
    Route::get('/', '[email protected]')->name('event.index'); 
    Route::post('load-more-ajax/{region?}', '[email protected]'); 
    Route::any('sorted-ajax/{region?}', '[email protected]'); 
    Route::get('category/{category_slug}/{subcategory_slug?}', '[email protected]'); 
    Route::get('{slug}', '[email protected]')->name('event.show'); 
    Route::get('{slug}/edit', '[email protected]')->name('event.edit'); 
});