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 :: validate audio file in laravel 
Php :: insert rows in migrations laravel 
Php :: while loop in laravel 
Php :: laravel redirect back 
Php :: laravel validation integer 
Php :: php pop off the first character of string 
Php :: increase the number in php by a certain percentage 
Php :: wordpress disable editor 
Php :: laravel fillable 
Php :: get the href in string regex php 
Php :: laravel destroy session 
Php :: artisan call migrate result 
Php :: laravel where between cluse 
Php :: laravel random column with limit 
Php :: link js file in php 
Php :: woocommerce remove related products 
Php :: use wordpress functions in external php file 
Php :: The blade is not updated with minor changes to the first blade 
Php :: laravel Postcontroller.php 
Php :: wordpress add submenu 
Php :: laravel tinker factory 
Php :: php get day diff 
Php :: difference between two timestamps php 
Php :: laravel migrate specific file 
Php :: change php version in ubuntu 
Php :: pathtophp in ubuntu lampp in moodle 
Php :: current page link using php 
Php :: facebook neuer name 
Php :: laravel join query sum example 
Php :: laravel faker examples 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =