laravel-composite-key icon indicating copy to clipboard operation
laravel-composite-key copied to clipboard

How to use HasCompositeKey in model

Open muazzamazaz opened this issue 5 years ago • 0 comments

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();

muazzamazaz avatar May 08 '19 11:05 muazzamazaz