At my last company this is something similar to what we did, how you implement it is up to you! I suggest changing some things around, it's designed to suit multiple types of voucher code, multi-use vouchers etc... To key past your primary key constraint we used big integer primary keys.
Schema::create( 'vouchers', function ( Blueprint $table ) {
$table->bigIncrements( 'id' );
// The voucher code
$table->string( 'code' )->nullable( );
// The human readable voucher code name
$table->string( 'name' );
// The description of the voucher - Not necessary
$table->text( 'description' )->nullable( );
// The number of uses currently
$table->integer( 'uses' )->unsigned( )->nullable( );
// The max uses this voucher has
$table->integer( 'max_uses' )->unsigned()->nullable( );
// How many times a user can use this voucher.
$table->integer( 'max_uses_user' )->unsigned( )->nullable( );
// The type can be: voucher, discount, sale. What ever you want.
$table->tinyInteger( 'type' )->unsigned( );
// The amount to discount by (in pennies) in this example.
$table->integer( 'discount_amount' );
// Whether or not the voucher is a percentage or a fixed price.
$table->boolean( 'is_fixed' )->default( true );
// When the voucher begins
$table->timestamp( 'starts_at' );
// When the voucher ends
$table->timestamp( 'expires_at' );
// You know what this is...
$table->timestamps( );
// We like to horde data.
$table->softDeletes( );
});
Schema::create( 'user_voucher', function ( Blueprint $table ) {
$table->integer( 'user_id' )->unsigned( );
$table->bigInteger( 'voucher_id' )->unsigned( );
$table->unique( [ 'user_id', 'voucher_id' ] );
});
Schema::create( 'product_voucher', function ( Blueprint $table ) {
$table->integer( 'product_id' )->unsigned( );
$table->bigInteger( 'voucher_id' )->unsigned( );
$table->unique( [ 'product_id', 'voucher_id' ] );
});
I hope this helps :)