first upload all files
This commit is contained in:
13
Modules/Coupon/Database/Factories/ModelFactory.php
Normal file
13
Modules/Coupon/Database/Factories/ModelFactory.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
use Modules\Coupon\Entities\Coupon;
|
||||
|
||||
$factory->define(Coupon::class, function (Faker\Generator $faker) {
|
||||
return [
|
||||
'name' => $faker->word(),
|
||||
'code' => $faker->word(),
|
||||
'value' => $faker->randomNumber(),
|
||||
'is_percent' => $faker->boolean(),
|
||||
'is_active' => $faker->boolean(),
|
||||
];
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCouponsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('coupons', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->string('code')->index();
|
||||
$table->decimal('value', 18, 4)->unsigned()->nullable();
|
||||
$table->boolean('is_percent');
|
||||
$table->boolean('free_shipping');
|
||||
$table->decimal('minimum_spend', 18, 4)->unsigned()->nullable();
|
||||
$table->decimal('maximum_spend', 18, 4)->unsigned()->nullable();
|
||||
$table->integer('usage_limit_per_coupon')->unsigned()->nullable();
|
||||
$table->integer('usage_limit_per_customer')->unsigned()->nullable();
|
||||
$table->integer('used')->default(0);
|
||||
$table->boolean('is_active');
|
||||
$table->date('start_date')->nullable();
|
||||
$table->date('end_date')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('coupons');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCouponTranslationsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('coupon_translations', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('coupon_id')->unsigned();
|
||||
$table->string('locale');
|
||||
$table->string('name');
|
||||
|
||||
$table->unique(['coupon_id', 'locale']);
|
||||
$table->foreign('coupon_id')->references('id')->on('coupons')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('coupon_translations');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCouponProductsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('coupon_products', function (Blueprint $table) {
|
||||
$table->integer('coupon_id')->unsigned();
|
||||
$table->integer('product_id')->unsigned();
|
||||
$table->boolean('exclude')->default(false);
|
||||
|
||||
$table->primary(['coupon_id', 'product_id']);
|
||||
$table->foreign('coupon_id')->references('id')->on('coupons')->onDelete('cascade');
|
||||
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('coupon_products');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateCouponCategoriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('coupon_categories', function (Blueprint $table) {
|
||||
$table->integer('coupon_id')->unsigned();
|
||||
$table->integer('category_id')->unsigned();
|
||||
$table->boolean('exclude')->default(false);
|
||||
|
||||
$table->primary(['coupon_id', 'category_id', 'exclude']);
|
||||
$table->foreign('coupon_id')->references('id')->on('coupons')->onDelete('cascade');
|
||||
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('coupon_categories');
|
||||
}
|
||||
}
|
||||
19
Modules/Coupon/Database/Seeders/CouponDatabaseSeeder.php
Normal file
19
Modules/Coupon/Database/Seeders/CouponDatabaseSeeder.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Modules\Coupon\Entities\Coupon;
|
||||
|
||||
class CouponDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
factory(Coupon::class, 10)->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user