반응형

라라벨을 하면서 모든 테이블을 라라벨에서 새롭게 생성해서 하는 경우라면 이 글을 읽을 필요는 없을 거다.

 

그런데 기존에 만들어 놓은 테이블이 있었고 그 테이블을 라라벨에 등록해서 사용하고 싶은 경우 즉 기존에 라라벨이 아니었다가 라라벨로 변경하는 경우에는 유용하게 쓰일 수 있겠다.

 

우선 설치를 한다.

 

$composer require "laracademy/generators" --dev

 

설치를 하면 거의 끝이다.

 

$php artisan generate:modelfromtable --table=users

 

이렇게 해주면 /App/model 폴더 아래에서 users 모델 파일이 생긴다. 그런데 만약 qa_users라는 테이블이 있었다면 이 테이블도 모델을 만들어 준다. 이름이 같은건 다 만들어 주는것 같다.

 

$php artisan generate:modelfromtable --table=users,posts

$php artisan generate:modelfromtable --table=user --folder=app/Models

 

이렇게 여러개의 테이블을 선택하거나 모델 파일의 경로를 지정해 줄 수도 있다.

 

자세한건 아래 사이트를 참조하자. 공식 페이지다.

 

https://github.com/laracademy/generators

 

GitHub - laracademy/generators: Laravel Generators

Laravel Generators. Contribute to laracademy/generators development by creating an account on GitHub.

github.com

 

 

반응형

+ Recent posts