laravel-composite-key
laravel-composite-key copied to clipboard
How to use HasCompositeKey in model
I am getting following error
App\Traits\HasCompositeKey::setKeysForSaveQueryMissing part of the primary key: destination_id
Model:
namespace App\Models;
use App\Traits\HasCompositeKey;
use Illuminate\Database\Eloquent\Model;
class Commission extends Model
{
use HasCompositeKey;
protected $table = 'commission';
protected $primaryKey = ['destination_id','effective_date'];
public $incrementing = false;
protected $fillable = [
'destination_id',
'effective_date',
'ticketPrice',
'commPercentage',
];
public function Destination()
{
return $this->belongsTo('App\Models\Destination');
}
}
Controller:
$commission = Commission::where('destination_id',$id)->where('effective_date',$request->effective_date)->first();
$input = Input::only('destination_id','effective_date', 'ticketPrice','commPercentage');
$commission->fill($input)->save();