
This tutorial will show you how to create a online shop with alipay payment function in laravel framwork.
Install Laravel and installing other dependencies.
Content
- Laravel E-Commerce with Alipay Dualfun Develope Part I - Creating Database Objects
- Laravel E-Commerce with Alipay Dualfun Develope Part II - Creating Models
- Laravel E-Commerce with Alipay Dualfun Develope Part III - Views and Routes
- Laravel E-Commerce with Alipay Dualfun Develope Part IV - Controllers
- Laravel E-Commerce with Alipay Dualfun Develope Part V - Alipay Payment API
Creating Database Objects
For our online shop; we're going to need categories for products to be sorted into, products and accounts. We’ll also need orders and order items, to track which items have been sold.
Creating Migrations
$ php artisan migrate:make create_users_table $ php artisan migrate:make create_product_categories_table $ php artisan migrate:make create_products_table $ php artisan migrate:make create_product_pictures_table $ php artisan migrate:make create_product_comments_table $ php artisan migrate:make create_product_cart_table $ php artisan migrate:make create_product_order_table
app/database/migrations/xxxx_xx_xx_xxxx_create_users_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('email');
$table->string('password');
$table->string('username', 60)->nullable();
$table->string('nickname', 60)->nullable();
$table->string('sex',4)->nullable();
$table->text('bio')->nullable();
$table->string('born_year')->nullable();
$table->string('born_month')->nullable();
$table->string('born_day')->nullable();
$table->text('home_province')->nullable();
$table->text('home_city')->nullable();
$table->text('home_address')->nullable();
$table->string('alipay')->nullable();
$table->string('phone')->nullable();
$table->string('portrait')->nullable();
$table->string('remember_token')->nullable();
$table->boolean('is_admin')->default('0');
$table->timestamp('deleted_at')->nullable();
$table->timestamp('activated_at')->nullable();
$table->timestamp('signin_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
app/database/migrations/xxxx_xx_xx_xxxx_create_product_categories_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductCategoriesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_categories', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('sort_order');
$table->text('content')->nullable();
$table->string('thumbnails')->nullable();
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('product_categories');
}
}
app/database/migrations/xxxx_xx_xx_xxxx_create_products_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products', function(Blueprint $table)
{
$table->increments('id');
$table->string('category_id');
$table->string('user_id');
$table->text('title', 100);
$table->string('price',100);
$table->string('quantity',100)->nullable();
$table->text('slug', 255);
$table->text('province')->nullable();
$table->text('city')->nullable();
$table->text('content');
$table->string('thumbnails')->nullable();
$table->smallInteger('comments_count')->default('0');
$table->text('meta_title', 100);
$table->text('meta_description', 255);
$table->text('meta_keywords', 255);
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('products');
}
}
app/database/migrations/xxxx_xx_xx_xxxx_create_product_pictures_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductPicturesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_pictures', function(Blueprint $table)
{
$table->increments('id');
$table->string('product_id')->nullable();
$table->string('user_id');
$table->text('filename', 255);
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('product_pictures');
}
}
app/database/migrations/xxxx_xx_xx_xxxx_create_product_comments_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductCommentsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_comments', function(Blueprint $table)
{
$table->increments('id');
$table->string('user_id')->nullable();
$table->string('product_id');
$table->text('content');
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('product_comments');
}
}
app/database/migrations/xxxx_xx_xx_xxxx_create_product_cart_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductCartTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_cart', function(Blueprint $table)
{
$table->engine = "InnoDB";
$table->increments('id');
$table->integer('buyer_id');
$table->integer("seller_id");
$table->integer("product_id");
$table->integer("quantity");
$table->string("price", 60);
$table->string("payment", 60);
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_cart');
}
}
app/database/migrations/xxxx_xx_xx_xxxx_create_product_order_table.php
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductOrdersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('product_orders', function(Blueprint $table)
{
$table->engine = "InnoDB";
$table->increments('id');
$table->text('order_id');
$table->text('alipay_trade')->nullable();;
$table->integer('seller_id');
$table->integer("product_id");
$table->integer('customer_id');
$table->integer("quantity");
$table->string("price", 60);
$table->string("payment", 60);
$table->text("customer_address", 120);
$table->text("express_name", 120)->nullable();
$table->text("invoice_no", 120)->nullable();
$table->boolean('is_payment')->default('0');
$table->boolean('is_express')->default('0');
$table->boolean('is_checkout')->default('0');
$table->timestamp('deleted_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('product_orders');
}
}
$ php artisan migrate