
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
This file should be saved as app/models/User.php
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends BaseModel implements UserInterface, RemindableInterface
{
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
/**
* Database table (without prefix)
* @var string
*/
protected $table = 'users';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = true;
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->email;
}
/**
* Visitor: Get friendly signin date
* @return string
*/
public function getFriendlySigninAtAttribute()
{
if (is_null($this->signin_at))
return 'New account';
else
return friendly_date($this->signin_at);
}
/**
* Ajuster: Password
* @param string $value Not handle password string
* @return void
*/
public function setPasswordAttribute($value)
{
If the string passed in Hash encryption have been made, then no processing is repeated
$this->attributes['password'] = Hash::needsRehash($value) ? Hash::make($value) : $value;
}
/**
* Object: Orders
* @return void
*/
public function orders()
{
return $this->hasMany("Order");
}
// ...
}
This file should be saved as app/models/Product.php
<?php
use \Michelf\MarkdownExtra;
/**
* Product
*/
class Product extends BaseModel
{
/**
* Database table (without prefix)
* @var string
*/
protected $table = 'products';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = true;
/**
* ORM (Modeling object relationships): Product category
* @return object Category
*/
public function category()
{
return $this->belongsTo('ProductCategories', 'category_id');
}
/**
* ORM (Modeling object relationships): Seller
* @return object User
*/
public function user()
{
return $this->belongsTo('User', 'user_id');
}
/**
* ORM (Modeling object relationships): Comments of goods
* @return object Illuminate\Database\Eloquent\Collection
*/
public function comments()
{
return $this->hasMany('ProductComment', 'product_id');
}
/**
* ORM (Modeling object relationships): Picture of goods
* @return object Illuminate\Database\Eloquent\Collection
*/
public function pictures()
{
return $this->hasMany('ProductPictures', 'product_id');
}
// ...
}
This file should be saved as app/models/ProductCategories.php
<?php
/**
* Product categories
*/
class ProductCategories extends BaseModel
{
/**
* Database table (without prefix)
* @var string
*/
protected $table = 'product_categories';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = true;
/**
* ORM (Modeling object relationships): goods in product category
* @return object Illuminate\Database\Eloquent\Collection
*/
public function product()
{
return $this->hasMany('Product', 'category_id');
}
// ...
}
This file should be saved as app/models/ProductComment.php
<?php
/**
* Product comments
*/
class ProductComment extends BaseModel
{
/**
* Database table (Not include prefix)
* @var string
*/
protected $table = 'product_comments';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = true;
/**
* ORM (Modeling object relationships): product owner
* @return object Article
*/
public function product()
{
return $this->belongsTo('Product', 'product_id');
}
/**
* ORM (Modeling object relationships): comments author
* @return object User
*/
public function user()
{
return $this->belongsTo('User', 'user_id');
}
// ...
}
This file should be saved as app/models/ProductPictures.php
<?php
/**
* Product Pictures
*/
class ProductPictures extends BaseModel
{
/**
* Database table (without prefix)
* @var string
*/
protected $table = 'product_pictures';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = true;
/**
* Object-relational model: Vesting product
* @return object Product
*/
public function product()
{
return $this->belongsTo('Product', 'product_id');
}
// ...
}
This file should be saved as app/models/ProductOrder.php
<?php
use \Michelf\MarkdownExtra;
/**
* ProductOrder
*/
class ProductOrder extends BaseModel
{
/**
* Database table (without prefix)
* @var string
*/
protected $table = 'product_orders';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = true;
/**
* ORM (Modeling object relationships): Order
* @return object User
*/
public function order()
{
return $this->belongsTo('User', 'user_id');
}
// ...
}
This file should be saved as app/models/ShoppingCart.php
<?php
use \Michelf\MarkdownExtra;
/**
* ShoppingCart
*/
class ShoppingCart extends BaseModel
{
/**
* Database table (without prefix)
* @var string
*/
protected $table = 'product_cart';
/**
* Soft delete
* @var boolean
*/
protected $softDelete = false;
/**
* ORM (Modeling object relationships): Seller
* @return object User
*/
public function seller()
{
return $this->belongsTo('User', 'user_id');
}
// ...
}