“Laravel fasih ganda kunci utama” Kode Jawaban

Laravel fasih ganda kunci utama

protected $primaryKey = ['user_id', 'stock_id'];
public $incrementing = false;
Foolish Flamingo

Laravel fasih ganda kunci utama

/**
 * Set the keys for a save update query.
 *
 * @param  \Illuminate\Database\Eloquent\Builder  $query
 * @return \Illuminate\Database\Eloquent\Builder
 */
protected function setKeysForSaveQuery(Builder $query)
{
    $keys = $this->getKeyName();
    if(!is_array($keys)){
        return parent::setKeysForSaveQuery($query);
    }

    foreach($keys as $keyName){
        $query->where($keyName, '=', $this->getKeyForSaveQuery($keyName));
    }

    return $query;
}

/**
 * Get the primary key value for a save query.
 *
 * @param mixed $keyName
 * @return mixed
 */
protected function getKeyForSaveQuery($keyName = null)
{
    if(is_null($keyName)){
        $keyName = $this->getKeyName();
    }

    if (isset($this->original[$keyName])) {
        return $this->original[$keyName];
    }

    return $this->getAttribute($keyName);
}
Foolish Flamingo

Jawaban yang mirip dengan “Laravel fasih ganda kunci utama”

Pertanyaan yang mirip dengan “Laravel fasih ganda kunci utama”

Lebih banyak jawaban terkait untuk “Laravel fasih ganda kunci utama” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya