When defining composite primary keys then calling save on an instanced model, an exception is thrown.
ErrorException (E_UNKNOWN)
PDO::lastInsertId() expects parameter 1 to be string, array given
The error occurred at line 32
$id = $query->getConnection()->getPdo()->lastInsertId($sequence);
And here's the declaration of Model
class ActivityAttendance extends Eloquent {
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'activity_attendance';
/**
* The primary key of the table.
*
* @var string
*/
protected $primaryKey = array('activity_id', 'username');
/**
* The attributes of the model.
*
* @var array
*/
protected $guarded = array('activity_id', 'username', 'guests');
/**
* Disabled the `update_at` field in this table.
*
* @var boolean
*/
public $timestamps = false;
}
Here's the code to create new record in Controller class.
$attendance = new ActivityAttendance;
$attendance->activity_id = $activityId;
$attendance->username = $username;
$attendance->save();