태그 "모델" tricks

updated_at 컬럼 사용하지 않기
Laravel Eloquent는 timestamp 컬럼인 created_at, updated_at 에 대해서 자동으로 날짜를 설정하고, 갱신하는 작업을 수행하다. 이 중 created_at 컬럼은 사용하고, updated_at 컬럼은 사용하지 않을 경우에는…
Submitted 8 years ago in Eloquent
4114
0
0
Eager Loading 체이닝
User, Phone, Post 세 개의 모델이 있고, 다음의 관계를 갖는다고 가정하자. class User extends Eloquent { public function phone() { return $this->hasOne('Phone'); } publif function posts() { return $this->hasMany('Post'); } }…
Submitted 9 years ago in Eloquent
2987
0
0
모델의 날짜 출력 포맷 정하기
Eloquent의 Accessor를 사용해서 날짜의 출력 포맷을 정할 수 있다. class Post extends Eloquent { public function getUpdatedAtAttribute($value) { return Carbon::parse($value)->format('d/m/Y H:i:s'); } public function…
Submitted 10 years ago in Views, Eloquent
3282
0
0
Eloquent의 Accessors와 Mutators
DB에서 데이터를 읽을 때, 혹은 저장할 때 규칙을 정해서 값을 변환하고 싶을 때가 있다. 날짜를 읽을 때 YYYY-MM-DD의 문자열로 바꾼다든지, 비밀번호를 저장할 때 해시코드로 저장하든지 등을…
Submitted 10 years ago in Eloquent
2544
0
0
DB 테이블에 기본 timestamps 컬럼 외에 다른 날짜타입 컬럼 추가하기
블로그 글을 담고 있는 posts 테이블이 있고, 다음과 같이 컬럼이 구성되어 있다. Schema::create('posts', function($table) { $table->increments('id'); $table->string('title'); $table->timestamps(); // 마지막 수정일…
Submitted 10 years ago in Eloquent
3340
0
0
timestamps 컬럼명 지정하기
timestamps를 사용하는 경우 (default) created_at, updated_at, deleted_at 컬럼명이 기본인데, 다음의 방법으로 이를 변경할 수 있다. 방법 1 User extends Eloquent{ const CREATED_AT = 'registered_at'; const UPDATED_AT =…
Submitted 10 years ago in Eloquent
3372
0
0
Laravel-4-Generator Cheat Sheet
Laravel 필수 패키지 중 하나인 Laravel-4-Generators의 Cheat Sheet $ php artisan generate:migration create_posts_table $ php artisan generate:migration create_posts_table --fields="title:string, body:text” $ php artisan…
Submitted 10 years ago in Packages
2348
0
1