Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session @Laravel5.2, @Laravel.5.2.27 #10

Open
appkr opened this issue Feb 12, 2016 · 1 comment
Open

Session @Laravel5.2, @Laravel.5.2.27 #10

appkr opened this issue Feb 12, 2016 · 1 comment

Comments

@appkr
Copy link
Owner

appkr commented Feb 12, 2016

최근에 이 강좌를 따라하시는 분이라면, $ laravel new myProject 명령으로 새로운 프로젝트를 생성했을 때 5.2 버전이 설치될 것입니다.

이 때 5.2 버전 부터 도입된 $middlewareGroups 때문에 세션이 유지되지 않는 (== 로그인이 되지 않는) 문제가 있을 겁니다.

해결하는 방법은

  1. 라우팅 정의를 Route::group(['middleware' => ['web']], function () { /* 라우팅 정의는 여기에.. */ }); 로 싸주거나,
// app/Http/route.php

Route::group(['middleware' => ['web']], function () {
  // Routing definition here...
});
  1. $middlewareGroups 속성을 쓰지 않는 방법입니다.
// app/Http/Kernel.php

protected $middleware = [
    \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\VerifyCsrfToken::class,
];

// protected $middlewareGroups = [
//     'web' => [
//         \App\Http\Middleware\EncryptCookies::class,
//         \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
//         \Illuminate\Session\Middleware\StartSession::class,
//         \Illuminate\View\Middleware\ShareErrorsFromSession::class,
//         \App\Http\Middleware\VerifyCsrfToken::class,
//     ],
// 
//     'api' => [
//         'throttle:60,1',
//     ],
// ];

이 강좌가 5.1 기준으로 쓰여졌으므로, 우선 2 의 방법을 사용하실 것을 권장합니다.

Happy coding~

@appkr
Copy link
Owner Author

appkr commented Apr 4, 2016

라라벨 5.2.27부터는 'web' 미들웨어가 기본 적용됩니다. 이 동작은 app/Providers/RouterServiceProvider.php의 변경때문에 발생합니다.

// app/Http/routes.php

Route::get('/', function () {
  return 'Hello World!';
});
$ php artisan route:list
+--------+-----------+-----+------+---------+------------+
| Domain | Method    | URI | Name | Action  | Middleware |
+--------+-----------+-----+------+---------+------------+
|        | GET|HEAD  | /   |      | Closure | web        |
+--------+-----------+-----+------+---------+------------+

라라벨은 laravel/laravel, laravel/framework 두개의 패키지로 구성됩니다. 라라벨 5.2.27이란 두개의 패키지 모두가 버전 5.2.27 이상일 때를 말합니다.

2016-3-27 이전에 새로 만들어 작업하던 프로젝트에서 $ composer update를 하면 laravel/framework패키지만 업데이트됩니다. 즉, laravel/laravel 패키지의 app/Providers/RouteServiceProvider.php 파일은 변경이 없으므로, 기존 라우팅 코드를 그대로 두셔됩니다.

@appkr appkr changed the title Session @Laravel5.2 Session @Laravel5.2, @Laravel.5.2.27 Apr 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant