Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel eloquent multiple primary key

/**
 * Set the keys for a save update query.
 *
 * @param  IlluminateDatabaseEloquentBuilder  $query
 * @return IlluminateDatabaseEloquentBuilder
 */
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);
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #laravel #eloquent #multiple #primary #key
ADD COMMENT
Topic
Name
2+7 =