πŸ₯•
TIL
  • [TIL] Studying tech / computer science knowledge
  • KeyMap
  • μ•Œκ³ λ¦¬μ¦˜
    • λ³΅μž‘λ„ 계산 ( Computational Complexity )
    • DisjointSet-unionFind
    • Bellman-ford Algorithm
    • Dijkstra's Algorithm
    • DP ( Dynamic Programming , 동적 κ³„νšλ²• )
    • ν”Œλ‘œμ΄λ“œ-μ›Œμ…œ μ•Œκ³ λ¦¬μ¦˜ (Floyd-Warshall algorithm)
    • Kruskal's Algorithm
    • 졜μž₯ 증가 μˆ˜μ—΄ (Longes Increasing Subsequence)
    • Prim's Algorithm
    • μ •λ ¬
    • μ‹œκ°„λ³΅μž‘λ„ 와 κ³΅κ°„λ³΅μž‘λ„ ( Time Complexity & Space Complexity )
    • Topological Sort (μœ„μƒ μ •λ ¬)
  • μ±… μ½κ³ λ‚œ ν›„ μš”μ•½
    • ν”„λ‘œκ·Έλž˜λ° λŒ€νšŒμ—μ„œ λ°°μš°λŠ” μ•Œκ³ λ¦¬μ¦˜ λ¬Έμ œν•΄κ²° μ „λž΅
    • cleancode
    • 도메인 주도 μ„€κ³„λ‘œ μ‹œμž‘ν•˜λŠ” λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€ 개발
    • 였브젝트
  • CDC
    • debzium
    • kafka
  • 개발 상식
    • asciidoctor
    • 컴파일러
    • ELK μŠ€νƒ
    • μ—”λ””μ•ˆ
    • git
    • Gitmoji
    • ν…ŒμŠ€νŠΈ μ’…λ₯˜
    • λΌμ΄λΈŒλŸ¬λ¦¬μ™€ ν”„λ ˆμž„μ›Œν¬
    • μ •κ·œ ν‘œν˜„μ‹
    • REST API
    • 동기와 비동기 / Blockingκ³Ό NonBlocking
    • Transaction Script와 Domain Model
    • λ””μžμΈ νŒ¨ν„΄
      • 행동 νŒ¨ν„΄
      • 객체 생성 νŒ¨ν„΄
        • 좔상 νŒ©ν† λ¦¬ νŒ¨ν„΄
        • λΉŒλ” νŒ¨ν„΄
        • νŒ©ν† λ¦¬ λ©”μ„œλ“œ νŒ¨ν„΄
        • [생성 νŒ¨ν„΄] ν”„λ‘œν†  νƒ€μž… (Prototype Parttern)
        • 싱글톀
      • ꡬ쑰 νŒ¨ν„΄
        • μ–΄λŒ‘ν„° νŒ¨ν„΄
        • λΈŒλ¦Ώμ§€ νŒ¨ν„΄
        • 컴포짓(Composite) νŒ¨ν„΄
        • λ°μ½”λ ˆμ΄ν„°
        • ν”„λ‘μ‹œ
    • refactoring
      • 쀑볡 μ½”λ“œ
      • μ „μ—­ 데이터
      • κΈ΄ ν•¨μˆ˜
      • κΈ΄ λ§€κ°œλ³€μˆ˜ λͺ©λ‘
      • κ°€λ³€ 데이터
      • μ΄ν•΄ν•˜κΈ° νž˜λ“  이름
  • 자료ꡬ쑰
    • AVL Tree
    • Splay Tree
    • aaTree
    • array-list
    • 자료ꡬ쑰 μ‹œκ°„/곡간 λ³΅μž‘λ„
    • κ·Έλž˜ν”„
    • νž™
    • Red Black Tree
    • stack-queue
    • 트리 ( Tree )
  • DevOps
    • MSA
    • Kubernetes
      • AccessingAPI
      • controller
      • dashboard
      • kubernetes
      • object
      • pod
      • service
      • volume
  • Java
    • μ–΄λ…Έν…Œμ΄μ…˜
    • μ œμ–΄λ¬Έ
    • 데이터 νƒ€μž…
    • Enum
    • jvm
    • μ—°μ‚°μž
    • thread
    • Java8
      • CompletableFuture
      • Date/Time
      • μ–΄λ…Έν…Œμ΄μ…˜κ³Ό λ©”νƒ€μŠ€νŽ˜μ΄μŠ€
      • μΈν„°νŽ˜μ΄μŠ€
      • λžŒλ‹€μ‹
      • Optional
      • 슀트림
  • JavaScript
    • moduleProject
    • webpack-babel
    • μ½”μ–΄ μžλ°”μŠ€ν¬λ¦½νŠΈ
      • array
      • ν•¨μˆ˜ 바인딩
      • λ°μ½”λ ˆμ΄ν„°μ™€ ν¬μ›Œλ”©
      • Class
      • 비ꡐ μ—°μ‚°μž
      • Date λ‚΄μž₯ 객체
      • destructuring-assignment
      • function
      • ν•¨μˆ˜μ˜ prototype ν”„λ‘œνΌν‹°
      • κ°€λΉ„μ§€ μ»¬λ ‰μ…˜ ( Garbage Collection )
      • JSON (JavaScript Object Notation)
      • map-set
      • λ‚΄μž₯ ν”„λ‘œν† νƒ€μž…
      • newμ—°μ‚°μžμ™€ μƒμ„±μž ν•¨μˆ˜
      • 객체
      • Object.keys, values, entries
      • μ˜΅μ…”λ„ 체이닝 '?.'
      • ν”„λ‘œνΌν‹° ν”Œλž˜κ·Έ
      • ν”„λ‘œνΌν‹° μ’…λ₯˜
      • ν”„λ‘œν†  νƒ€μž…
      • 호좜 μŠ€μΌ€μ€„λ§ ( scheduling a call )
      • scope
      • this
      • type-conversions
      • type
      • ν•¨μˆ˜μ˜ μžλ£Œν˜•
      • var_let_const
  • Linux
    • κΈ°λ³Έ λͺ…λ Ήμ–΄
    • 파일 μ’…λ₯˜
    • λ¦¬λˆ…μŠ€
  • λ„€νŠΈμ›Œν¬
    • μ‘μš© 계측 ( Application Layer )
    • 였λ₯˜ κ²€μΆœκ³Ό 였λ₯˜ μ •μ •
    • Http
    • Http Header
    • 컴퓨터 λ„€νŠΈμ›Œν¬λž€
    • λ„€νŠΈμ›Œν¬ 계측
    • λ„€νŠΈμ›Œν¬ μ œμ–΄ μ˜μ—­
    • 전솑 계측 ( Transport Layer )
  • PHP
    • Facade
    • composer
    • scopeResolutionOperator
    • Laravel
      • SocialProvider
      • architecture
      • blade
      • controller
      • db
      • dbArchitecture
      • debug
      • eloquent
      • email
      • event
      • exceptionHandling
      • middleware
      • model
      • modelFactory
      • pagingLoading
      • queryBuilder
      • route
      • scout
      • seeding
      • tntsearch
      • validate
      • view
  • React
    • Next.js
    • React λž€?
  • Spring
    • Controller
    • μš”μ²­μ΄ λ“€μ–΄μ™”μ„λ•Œ μŠ€ν”„λ§μ΄ μ²˜λ¦¬ν•˜λŠ” 방법 ( 내뢀ꡬ쑰 )
    • ConfigurationProperties
    • Entity / DTO / VO
    • Maven
    • Repository와 DAO
    • μŠ€ν”„λ§ 빈
    • Spring Framework
    • MVC νŒ¨ν„΄
    • 도메인 μž…λ ₯κ°’ 검증
    • Spring Cloud
      • Spring Cloud
      • Eureka
    • Spring Data
      • JPA
      • JPA μ–΄λ…Έν…Œμ΄μ…˜
      • μ—”ν‹°ν‹° 비ꡐ
      • 볡합 킀와 식별 관계 λ§€ν•‘
      • JPA μ˜ˆμ™Έμ²˜λ¦¬
      • 객체지ν–₯ 쿼리
      • EntityManagerFactory와 EntityManager
      • JPA μ΅œμ ν™”
      • ν”„λ‘μ‹œμ™€ 연관관계 λ§΅ν•‘
      • 연관관계
      • 상속관계 λ§΅ν•‘
      • νŠΈλžœμž­μ…˜ λ²”μœ„μ™€ μ˜μ†μ„± μ»¨ν…μŠ€νŠΈ
      • 데이터 νƒ€μž…
      • MySQL μ—°κ²°
      • Pageable
    • Spring Projectλ“€κ³Ό library
      • Custom Serialize
      • Elasticsearch Index API
      • Spring HATEOAS
      • lombok (둬볡)
      • Model Mapper
      • Object Mapper
      • Representation Model
      • Spring REST Docs
      • Spring Boot
    • Spring Security
      • Spring Security
      • Authentication
      • Authentication Filter
      • Authorization Filter
      • Filter Chain
      • SecurityContext
      • Spring OAuth2.0
    • Spring Test
      • AssertJ
      • Junit5
      • JunitParams
      • Mock Object
  • DataBase
    • ALIAS
    • CONCAT
    • CTE
    • Group By
    • HAVING
    • IFNULL
    • 인덱슀
    • JOIN
    • ORDER BY
    • ROLLUP
    • SELECT
    • SELECT DISTINCT
    • SQL
    • WHERE
  • Web 상식
    • OAuth
    • WAS
    • HTTP톡신 기반 인증
    • λΈŒλΌμš°μ €
    • CSR κ³Ό SSR
    • HTTPS
    • Web
Powered by GitBook
On this page
  • μ—˜λ‘œν€€νŠΈ
  • 연관관계
  • 쑰회
  • cursor()
  • μ‚½μž…
  • 속성 λ³€κ²½ 확인
  • λŒ€λŸ‰ ν• λ‹Ή
  1. PHP
  2. Laravel

eloquent

μ—˜λ‘œν€€νŠΈ

라라벨이 μ œκ³΅ν•˜λŠ” ORMκ΅¬ν˜„μ²΄λ‘œ DB와 객체간 λ§΅ν•‘κΈ°μˆ 

쿼리

>>> $post = App\Models\Post::get();

λͺ¨λΈ 클래슀λ₯Ό μ΄μš©ν•΄μ„œ μΏΌλ¦¬λΉŒλ”μ™€ 같이 λ©”μ„œλ“œλ‘œ 쿼리λ₯Ό μˆ˜ν–‰ν•  수 μžˆλŠ”λ° μ΄λŠ” Model클래슀λ₯Ό 상속받기 λ•Œλ¬Έμ— λ©”μ„œλ“œλ₯Ό μ΄μš©ν•  수 μžˆλ‹€.

save()

>>> $post = App\Models\Post::first();
>>> $post->title = 'foo';
>>> $post->save();  //errorλ°œμƒ

μœ„μ—μ„œ save()λ₯Ό μ‹€ν–‰ν•˜λ©΄ μ˜ˆμ™Έκ°€ λ°œμƒν•˜λŠ”λ°, μ—˜λ‘œν€€νŠΈλŠ” λͺ¨λ“  ν…Œμ΄λΈ”μ— created_at,updated_at이 μžˆλ‹€κ³  κ³Όμ •ν•˜κ³  ν˜„μž¬μ˜ νƒ€μž„μŠ€νƒ¬ν”„κ°’μ„ ν• λ‹Ήν•˜λŠ”λ° ν•΄λ‹Ή 컬럼이 μ‘΄μž¬ν•˜μ§€ μ•Šμ•„ λ°œμƒν•˜λŠ” μ—λŸ¬μ΄λ‹€. ν•΄λ‹Ή μ»¬λŸΌμ„ μΆ”κ°€ν•΄μ£Όκ±°λ‚˜ νƒ€μž„μŠ€νƒ¬ν”„ μžλ™μž…λ ₯κΈ°λŠ₯을 λ„λŠ” λ°©λ²•μœΌλ‘œ ν•΄κ²°ν•  수 μžˆλ‹€.

public $timestamps = false;을 μΆ”κ°€ν•΄ μžλ™μž…λ ₯κΈ°λŠ₯을 끌 수 μžˆλ‹€.

create()

save()λ©”μ„œλ“œλŠ” λͺ¨λΈμ˜ ν”„λ‘œνΌν‹° 값을 ν•˜λ‚˜μ”© ν• λ‹Ήν•΄μ£Όμ–΄μ•Ό ν•˜λŠ”λ° μ—¬λŸ¬κ°œμ˜ ν”„λ‘œνΌν‹°κ°’μ„ ν•œλ²ˆμ— ν• λ‹Ήν•˜λŠ” κ²½μš°μ—λŠ” create()λ₯Ό μ‚¬μš©ν•˜λ©΄ νŽΈν•˜κ²Œ μž‘μ—…ν•  수 μžˆλ‹€.

>>> App\Models\Post::create([
    'email' => 'test@test.com',
    'password' => 'bcrypt('1234')',
]);

create()λ©”μ„œλ“œλ₯Ό μ΄μš©ν•΄ λ§€κ°œλ³€μˆ˜λ‘œ associate arrayλ₯Ό λ„˜κ²¨μ£Όμ–΄ 값을 ν• λ‹Ήν•΄ 쀄 수 μžˆλ‹€.

bcrypt()λŠ” 60λ°”μ΄νŠΈμ§œλ¦¬ 단방ν–₯ ν•΄μ‹œλ₯Ό λ§Œλ“œλŠ” λ„μš°λ―Έ ν•¨μˆ˜λ‘œ λ³΅ν˜Έν™”κ°€ λΆˆκ°€λŠ₯ν•˜κΈ°λ•Œλ¬Έμ— λΉ„λ°€λ²ˆν˜Έ μ°ΎκΈ°κ°€ λΆˆκ°€λŠ₯ν•˜λ‹€.

μœ„ μ½”λ“œλ₯Ό μ‹€ν–‰μ‹œμΌœλ³΄λ©΄ MassAssignmentException이 λ°œμƒν•˜λŠ”λ° μ΄λŠ” μ—˜λ‘œν€€νŠΈ μžμ²΄μ—μ„œ ν•΄μ»€μ˜ λŒ€λŸ‰ ν• λ‹Ή 곡격을 λ³΄ν˜Έν•˜κΈ° μœ„ν•œ μ˜ˆμ™Έμ΄λ‹€. 이λ₯Ό μœ„ν•΄μ„œλŠ” 두가지 방법을 μ œκ³΅ν•˜λŠ”λ° ν•˜λ‚˜λŠ” $fillable ν”„λ‘œνΌν‹°λ₯Ό μ΄μš©ν•˜λŠ” ν—ˆμš©λͺ©λ‘ 방식이고, ν•˜λ‚˜λŠ” $guardedν”„λ‘œνΌν‹°λ₯Ό μ΄μš©ν•œ κΈˆμ§€λͺ©λ‘ 방식이닀.

연관관계

1. μΌλŒ€λ‹€ 관계

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
{
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('user_id')->unsigned()->index();
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

λ§ˆμ΄κ·Έλ ˆμ΄μ…˜μ—μ„œ λ‹€(N)κ°€ λ˜λŠ” μͺ½μ— foreign()λ©”μ„œλ“œλ₯Ό μ΄μš©ν•΄μ„œ ν…Œμ΄λΈ”λΌλ¦¬μ˜ μ™Έλž˜ ν‚€ 관계λ₯Ό μ—°κ²° ν•΄μ£Όκ³  λͺ¨λΈμ—μ„œ μ•„λž˜μ™€ 같이 연결관계λ₯Ό ν‘œν˜„ν•΄μ£Όλ©΄ λœλ‹€.

//User
class User extends Authenticatable
{
    use HasFactory, Notifiable;

    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    protected $hidden = [
        'password',
        'remember_token',
    ];

    public function posts(){
        return $this->hasMany(Post::class);
    }
}

//Post
class Post extends Model
{
    use HasFactory;

    protected $fillable = [
        'title',
        'body',
    ];

    public $timestamps = false;

    public function user(){
        return $this->belongsTo(User::class,'custom_user_id');
    }
}

각 λͺ¨λΈλ‚΄μ—μ„œ 연관관계섀정할 λͺ¨λΈμ΄λ¦„μ˜ λ©”μ„œλ“œλ₯Ό λ§Œλ“€μ–΄ hasMany(), belongsTo()λ©”μ„œλ“œμ™€ 같이 μ ‘κ·Ό ν•  수 있게 μ •μ˜ 해쀄 수 μžˆλŠ”λ° μ΄λ•Œ λ©”μ„œλ“œ λͺ…μœΌλ‘œ 관둀상 1이 λ˜λŠ” μͺ½ λͺ¨λΈμ„ μ ‘κ·Όν•˜λŠ” λ©”μ„œλ“œλŠ” λ‹¨μˆ˜, N이 λ˜λŠ” λͺ¨λΈμ„ μ ‘κ·Όν•˜λŠ” λ©”μ„œλ“œλŠ” 볡수λ₯Ό μ‚¬μš©ν•œλ‹€. 1μ΄λ˜λŠ”μͺ½μ—μ„œ N을 μ—°κ²°ν• λ•Œ hasMany()λ₯Ό, N이 λ˜λŠ”μͺ½μ—μ„œ 1을 μ—°κ²°ν• λ•Œ belongsTo()λ₯Ό μ΄μš©ν•œλ‹€.

μ™Έλž˜ν‚€ 이름은 λͺ¨λΈλͺ…을 κ°€μ§€κ³  μ—˜λ¦¬ν€€νŠΈκ°€ μœ μΆ”ν•˜μ—¬ μ—°κ²°ν•˜μ§€λ§Œ νŠΉλ³„ν•œ id둜 연결을 μ›ν•œλ‹€λ©΄ Postλͺ¨λΈμ˜ user()κ³Ό 같이 λ§€κ°œλ³€μˆ˜λ‘œ μ™Έλž˜ν‚€ 이름을 지정해쀄 수 μžˆλ‹€.

λ‹€λŒ€λ‹€ μ—°κ²°

$ php artisan make:migration create_article_tag_table --create=article_tag

class CreateArticleTagTable extends Migration
{
    public function up()
    {
        Schema::create('article_tag', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('article_id')->unsigned();
            $table->integer('tag_id')->unsigned();

            $table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');
            $table->foreign('tag_id')->references('id')->on('articles')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('article_tag');
    }
}

N:N관계λ₯Ό μ—°κ²°ν•˜κΈ° μœ„ν•΄μ„œλŠ” ν…Œμ΄λΈ” ν•œκ°œλ₯Ό 더 생성해주어야 ν•œλ‹€.

//Post
class Post extends Model
{
    use HasFactory;

    public $timestamps = false;

    protected $fillable = [
        'title',
        'body',
    ];

    public function user(){
        return $this->belongsTo(User::class,'custom_user_id');
    }

    public function tags(){
        return $this->belongsToMany(Tag::class);
    }
}

//tag
class Tag extends Authenticatable
{
    use HasFactory, Notifiable;

    protected $fillable = [
        'name'
    ];

    public function posts(){
        return $this->belongsToMany(Post::class);
    }
}

N:N은 μ–‘μͺ½ λ‹€ belongsToMany()λ₯Ό μ΄μš©ν•˜μ—¬ 연결을 ν•΄μ£Όλ©΄ λ˜λŠ”λ° μ²«λ²ˆμ§Έμ—μ„œ ν…Œμ΄λΈ”μ„ ν•œκ°œλ” μƒμ„±ν•˜λŠ” μ΄μœ λŠ” 이 ν…Œμ΄λΈ”μ΄ N:N관계λ₯Ό μ—°κ²°μ‹œμΌœμ£ΌλŠ” ν”Όλ²— ν…Œμ΄λΈ”μ΄ 되기 λ•Œλ¬Έμ΄λ‹€.

쑰회

all()

$flights = App\Models\Flight::all();

foreach ($flights as $flight) {
    echo $flight->name;
}

all()λ©”μ„œλ“œλ₯Ό 톡해 ν…Œμ΄λΈ”μ„ μ‘°νšŒν•  μˆ˜μžˆμ§€λ§Œ μ΄λŠ” λͺ¨λ“  행이 쑰회되기 λ•Œλ¬Έμ— μΏΌλ¦¬λΉŒλ”μ™€ λΉ„μŠ·ν•˜κ²Œ 쑰건듀을 μΆ”κ°€ν•  수 μžˆλ‹€.

μ—˜λ‘œν€€νŠΈ λͺ¨λΈμ€ λͺ¨λ‘ μΏΌλ¦¬λΉŒλ”μ΄κΈ° λ•Œλ¬Έμ— 쿼리 λΉŒλ”μ˜ λͺ¨λ“  λ©”μ„œλ“œλ₯Ό μ΄μš©ν•  수 μžˆλ‹€.

$flights = App\Models\Flight::where('active', 1)
               ->orderBy('name', 'desc')
               ->take(10)
               ->get();

cursor()

$users = App\Models\User::cursor()->filter(function ($user) {
    return $user->id > 500;
});

foreach ($users as $user) {
    echo $user->id;
}

cursorλ©”μ„œλ“œλŠ” λ‹¨ν•˜λ‚˜μ˜ 쿼리λ₯Ό 싀행을 톡해 λŒ€λŸ‰μ˜ 데이터λ₯Ό 처리 ν•  수 μžˆμ–΄ λ©”λͺ¨λ¦¬ μ‚¬μš©λŸ‰μ„ 크게 쀄일 수 μžˆλ‹€. μ΄λ•Œ λ°˜ν™˜κ°’μœΌλ‘œ LazyCollection을 λ°˜ν™˜ν•˜κΈ° λ•Œλ¬Έμ— Collection λ©”μ„œλ“œλ“€μ„ μ΄μš©ν•  수 μžˆλ‹€.

μ‚½μž…

$flight = new Flight;

$flight->name = $request->name;

$flight->save();

μΏΌλ¦¬λΉŒλ”μ˜ insert보닀 κ°„νŽΈν•˜κ²Œ save()λ©”μ„œλ“œλ‘œ μ‚½μž…μ„ μˆ˜ν–‰ν•  수 μžˆλ‹€. μ΄λ•Œ νƒ€μž„μŠ€νƒ¬ν”„λŠ” μžλ™μœΌλ‘œ μ„€μ •λ˜μ–΄ μˆ˜λ™μœΌλ‘œ μ§€μ •ν•  ν•„μš”κ°€ μ—†λ‹€.

λ˜ν•œ, 이미 μ‘΄μž¬ν•˜λŠ” 행이라면 updateλ₯Ό μˆ˜ν–‰ν•œλ‹€.

속성 λ³€κ²½ 확인

isDirty() | isClean()

$user = User::create([
    'first_name' => 'Taylor',
    'last_name' => 'Otwell',
    'title' => 'Developer',
]);

$user->title = 'Painter';

$user->isDirty(); // true
$user->isDirty('title'); // true
$user->isDirty('first_name'); // false

$user->isClean(); // false
$user->isClean('title'); // false
$user->isClean('first_name'); // true

$user->save();

$user->isDirty(); // false
$user->isClean(); // true

ν˜„μž¬ λͺ¨λΈμ΄ db에 flushκ°€ λ˜μ—ˆλŠ”μ§€ 각 μ»¬λŸΌλ³„λ‘œ 확인기 κ°€λŠ₯ν•˜λ‹€.

wasChanged()

$user = User::create([
    'first_name' => 'Taylor',
    'last_name' => 'Otwell',
    'title' => 'Developer',
]);

$user->title = 'Painter';
$user->save();

$user->wasChanged(); // true
$user->wasChanged('title'); // true
$user->wasChanged('first_name'); // false

ν˜„μž¬ μš”μ²­μ£ΌκΈ°λ‚΄μ— λͺ¨λΈμ˜ 속성이 λ³€κ²½λ˜μ—ˆλŠ”μ§€ ν™•μΈν•˜λŠ” λ©”μ„œλ“œ

getOriginal()

$user = User::find(1);

$user->name; // John
$user->email; // john@example.com

$user->name = "Jack";
$user->name; // Jack

$user->getOriginal('name'); // John
$user->getOriginal(); // Array of original attributes...

flush되기 μ „μ˜ λͺ¨λΈμ˜ μˆ˜μ •λœ 이전 값을 ν™•μΈν•˜λŠ” λ©”μ„œλ“œ

λŒ€λŸ‰ ν• λ‹Ή

λͺ¨λΈμ˜ κ°’ ν”„λ‘œνΌν‹°λ₯Ό 각각 μ±„μ›Œ save()둜 μ €μž₯ν•˜λŠ” 방법 외에 create()λ©”μ„œλ“œλ₯Ό μ΄μš©ν•˜μ—¬ ν•œλ²ˆμ— μ €μž₯ ν•  μˆ˜λ„ μžˆλ‹€.

$flight = App\Models\Flight::create(['name' => 'Flight 10']);

ν•˜μ§€λ§Œ, μ—˜λ‘œν€€νŠΈλŠ” 기본적으둜 λŒ€λŸ‰ ν• λ‹ΉμœΌλ‘œλΆ€ν„° λ³΄ν˜Έν•˜κΈ° λ•Œλ¬Έμ— μ‚¬μš©ν•  수 μ—†μ–΄ fillable속성에 μ»¬λŸΌλ“€μ„ μΆ”κ°€ν•΄μ£Όμ–΄μ•Ό ν•œλ‹€.

PreviousdebugNextemail

Last updated 3 years ago