라라벨 5.1 주요 변경 사항 및 업그레이드
주요 변경 사항
Blade 에서 Service Inject
블레이드에서 서비스 객체를 주입할 수 있습니다.
@inject('currentUser', 'App\User') {{ $currntUser->name }}
Model Factory
라라벨 model factory 로 DB Seeding 과 test 데이타 만들기
Command signature
손쉽게 커맨드에 옵션과 파라미터를 추가할 수 있습니다. (laravel artisan command 추가하기 참고)
5.0 에서 업그레이드
기존 5.0 프로젝트를 업그레이드하는 절차만 정리했고 패키지 변경으로 인한 기존 소스 수정은 http://laravel.com/docs/5.1/upgrade 를 참고하세요.
composer.json 의 laravel 버전을 5.1.* 로 변경하고 PHP 의 버전 의존성을 5.5.9 이상으로 설정합니다. 그리고 5.1 에 포함된 기능인 Model Factory 와 개선된 테스팅을 사용하기 위해 require-dev 에 faker 와 mockery 를 추가합니다.
"require": { "php": ">=5.5.9", "laravel/framework": "5.1.*", } "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.*", "phpunit/phpunit": "~4.0", "phpspec/phpspec": "~2.1" },
composer.json 을 수정하지 말고 라라벨 5.1 프로젝트를 생성한 후에 여기에 있는 composer.json 을 가져다가 사용해도 됩니다.
캐시 폴더 위치가 변경되었으므로 만들어 줍니다.
mkdir bootstrap/cache
bootstrap/cache/.gitignore 파일을 생성하고 이 파일을 git 에 추가하고 커밋합니다.
bootstrap/cache/.gitignore* !.gitignore
git 저장소에 추가$ git add bootstrap/cache/.gitignore $ git commit
cache 폴더는 라라벨 프레임워크가 사용하므로 php 를 구동하는 프로세스(mod_php 일 경우 apache, php-fpm 일 경우 php-fpm 구동 프로세스)가 쓰기 가능해야 하므로 권한을 부여합니다.
CentOS 에 적용setfacl -R -m u:apache:rwx bootstrap/cache
쓰기 권한이 없으면 라라벨이 제대로 동작하지 않을 수 있습니다.
bootstrap/autoload.php 의 compiledPath 변수를 수정합니다.
//if (file_exists($compiledPath = __DIR__.'/../vendor/compiled.php')) if (file_exists($compiledPath = __DIR__.'/cache/compiled.php'))
컴포저 업데이트를 실행합니다.
composer update
컴포저 업데이트를 해도 database/factories/ModelFactory.php 파일은 생성되지 않으므로 에디터에서 파일을 열고 다음 내용을 입력합니다. (Model Factory 를 사용할 때만 해당됩니다.)
라라벨 버전을 확인합니다.
$ php artisan --version Laravel Framework version 5.1.1 (LTS)
- 웹 서버를 재구동하고 정상 동작하는지 확인합니다.
Ref