Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel eloquent multiple primary key

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

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);
}
Comment

multiple primary key defined laravel

public function up()
{
    Schema::create('spins', function (Blueprint $table) {
        $table->engine = 'MyISAM';
        $table->integer('rid')->unsigned();
        $table->bigInteger('pid');
        $table->integer('result');
        $table->integer('bet');
        $table->timestamps();
        $table->primary(array('rid', 'pid'));

        DB::statement('ALTER TABLE spins MODIFY rid INTEGER NOT NULL AUTO_INCREMENT');
    });
}
Comment

PREVIOUS NEXT
Code Example
Php :: woocommerce php reset password length 
Php :: Trying to access variable outside laravel collection 
Php :: laravel reoute return string 
Php :: turn off wordpress user list exposed 
Php :: Uncaught Error: Call to undefined function add_submenu_page() 
Php :: what is composer in laravel 
Php :: php md5 password is insecure 
Php :: wp wc php if not is single product page 
Php :: change sender name laravel 
Php :: is search page wordpress dev 
Php :: get product price by id woocommerce snippet 
Php :: php $_session err_miss_cache 
Php :: php split 
Php :: PHP code to read JSON string on server 
Php :: switching between php versions 
Php :: if post checked category wordpress 
Php :: $faker-paragraph 
Php :: string put inside tag string php 
Php :: increase file upload size limit 
Php :: Call Python From PHP And Get Return Code 
Php :: php number formatter 
Php :: table laravel 
Php :: laravel route limit parameter 
Php :: php array remove the last element 
Php :: php header author 
Php :: laravel route regex except 
Php :: What template files are used for our custom post type in wordpress? 
Php :: php base58 decode 
Php :: php-array-delete-by-value-not-key 
Php :: php password_hash 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =