https://laravel-news.com/eloquent-tips-tricks : 정리

  1. Increments and Decrements : increment , decrement 로 값을 증감
  2. XorY Methods : if(find)-abort → findOrFail , if(first)-create → firstOrCreate
  3. Model boot() Method : 기본 동작이나 특정 이벤트를 위한 커스텀 로직을 추가
  4. Relationship with Conditions and Ordering : (관계 정의 시) 조건이나 정렬을 추가
  5. Model Properties : 모델의 다양한 기본 속성들
  6. Find Multiple Entries : find([1,2,3])
  7. whereX Methods : 필드명을 메서드명에 추가해 where 을 간단히 사용
  8. Order by Relationship : 4번을 응용하여 with, load 사용 시 정렬 가능
  9. Eloquent::when() : if-else 대신 when()
  10. BelongsTo Default Models : $post->author->name ?? '’ 대신 belongsTo 기본 모델을 설정
  11. Order by Mutator : get()->sortBy()
  12. Default Ordering in Global Scope : 글로벌 스코프로 기본 정렬을 설정
  13. Raw Query Methods : whereRaw, havingRaw, orderByRaw
  14. Replicate : 데이터(모델) 복제
  15. Chunk() Method for Big Tables : 큰 데이터셋을 처리할 때 chunk 사용
  16. Create Additional Things When Creating a Model : artisan make:model Company -mcr