muazzamazaz
4 months ago

How to use HasCompositeKey in model

Posted 4 months ago by muazzamazaz

I have added following package

https://github.com/mpociot/laravel-composite-key

into laravel and 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();

Please sign in or create an account to participate in this conversation.