-
php artisan make:model Contact -m 명령어와 옵션에 대한 설명백엔드/laravel 2024. 1. 21. 14:04
- php artisan make:model Contact:
- php artisan make:model 명령어는 Laravel에서 새로운 Eloquent 모델을 생성하는 데 사용됩니다.
- Contact는 모델의 이름입니다. 이 명령어를 실행하면 app/Models 디렉토리에 Contact.php 파일이 생성됩니다.
- Eloquent 모델은 데이터베이스 테이블과 상호 작용하는데 사용됩니다. 이 경우 Contact 모델은 contacts라는 이름의 데이터베이스 테이블과 연결됩니다.
- -m 또는 --migration 옵션:
- -m 옵션은 마이그레이션 파일도 함께 생성하도록 명령에게 지시합니다.
- 마이그레이션 파일은 데이터베이스 테이블을 생성하기 위한 스키마를 정의합니다.
- Contact 모델을 생성하는 동시에 database/migrations 디렉토리에 create_contacts_table.php 또는 유사한 이름의 마이그레이션 파일이 생성됩니다.
따라서 위 명령어를 실행하면 app/Models/Contact.php 파일과 database/migrations/create_contacts_table.php 파일이 생성됩니다. Contact 모델은 contacts 테이블과 연결되는 Eloquent 모델이 되며, 해당 마이그레이션 파일은 contacts 테이블을 생성하는데 사용됩니다.
public function up(): void
{
Schema::create('contacts', function (Blueprint $table) {
$table->id();
$table->foreignId(column: 'user_id')
->constrained(table: 'users')
->cascadeOnDelete();
$table->string(column: 'address');
$table->string(column: 'number');
$table->string(column: 'city');
$table->string(column: 'zip_code');
$table->unique(['address', 'zip_code']);
$table->timestamps();
});
}'백엔드 > laravel' 카테고리의 다른 글
라라벨 Eloquent One-to-Many Relationship (0) 2024.01.21 라라벨 Eloquent one-to-one Relationship (0) 2024.01.21 Laravel 모델의 Fillable 과 Guarded (0) 2024.01.20 Laravel Eloquent 모델 규칙과 설정 (0) 2024.01.20 Laravel에서 Eloquent ORM과 Query Builder 사용 비교 (0) 2024.01.20 - php artisan make:model Contact: