본문 바로가기

개발/laravel

[laravel5.5] 302 redirect status code

반응형

컨텐츠를 수정할 Controller를 작성한 후

 

Route::post('/contents-video-sort', 'ContentsController@changeLectureOrder');

 

프론트에서 호출하였을 때

 

axios.post("/contents-video-sort", 
    {list : this.list.data})
    .then(...)

아래와 같이 302 redirect error 가 나면서 호출이 되지 않는 문제가 발생하였다.

 

찾아보니 CSRF 문제일 수 있다고 했다.

https://stackoverflow.com/questions/42426859/laravel-ajax-post-request-does-not-work-302-found

 

Laravel Ajax POST Request does not work: 302 found

I'm trying to push some data via ajax in Laravel. Unfortunally it does not work. When I was watching at the network traffic, i found this: Request Method:POST Status Code:302 Found I'm trying to ...

stackoverflow.com

https://laravel.com/docs/5.5/csrf

 

Laravel - The PHP Framework For Web Artisans

Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.

laravel.com

 

하지만 헤더에 정상적으로 CSRF Token을 전달하고 있었다.

 

내 경우에는 middleware 문제였는데

로그인한 사용자의 권한을 관리하기 위해서 

authority 라는 middleware에서 권한별로 설정된 gnb에 명시되지 않은 route에 접근할 경우 

접근을 차단하고 있었다.

 

gnb는 노출되는 메뉴만을 관리하는데 왜 이렇게 했는지는 나도 모르겠으나..

어쨌든...컨트롤러에서 middleware->except로 해당 함수 호출 시 미들웨어 타지 않도록 하는 멍청한 방법으로 해결했다.

$this->middleware('authority')->except('changLectureOrder');

 

 

반응형

'개발 > laravel' 카테고리의 다른 글

라라벨 Sail 설정 가이드  (0) 2023.10.10
[Laravel] log permission denied  (0) 2023.07.11
[laravel 5.5/QueryBuilder] SubQuery  (0) 2022.08.30