laravel-promocodes icon indicating copy to clipboard operation
laravel-promocodes copied to clipboard

Column not found: 1054 Unknown column 'user_id' in 'field list'

Open SidneySaints opened this issue 2 years ago • 1 comments

Hi,

if you customize users foreign key in the config, create method throws an exception user_id column can not be found.

something like this do the trick:

 return $this->generate()->map(fn(string $code) => app(PromocodeContract::class)->create([
            config('promocodes.models.users.foreign_id') => optional($this->user)->id,
            'code' => $code,
            'usages_left' => $this->unlimited ? -1 : $this->usagesLeft,
            'bound_to_user' => $this->user || $this->boundToUser,
            'multi_use' => $this->multiUse,
            'details' => $this->details,
            'expired_at' => $this->expiredAt,
        ]));

SidneySaints avatar Nov 01 '22 20:11 SidneySaints

Have same problem

ArtMin96 avatar Oct 03 '23 10:10 ArtMin96