You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.7 KiB
69 lines
2.7 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\Models\Address
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $name 收货人名字
|
|
* @property string $phone 收货人手机号码
|
|
* @property string|null $province_id 省份
|
|
* @property string|null $city_id 城市
|
|
* @property string $detail_address 详细的收货地址
|
|
* @property int $is_default 是否是默认收货地址
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\City|null $city
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Order[] $orders
|
|
* @property-read \App\Models\Province|null $province
|
|
* @property-read \App\Models\User $user
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereCityId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereDetailAddress($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereIsDefault($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereName($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address wherePhone($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereProvinceId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Address whereUserId($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
class Address extends Model
|
|
{
|
|
protected $table = 'addresses';
|
|
protected $fillable = ['name', 'phone', 'province_id', 'city_id', 'detail_address', 'is_default', 'user_id'];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
return $this->hasMany(Order::class);
|
|
}
|
|
|
|
public function format()
|
|
{
|
|
return optional($this->province)->name . optional($this->city)->name. $this->detail_address;
|
|
}
|
|
|
|
public function province()
|
|
{
|
|
return $this->belongsTo(Province::class);
|
|
}
|
|
|
|
public function city()
|
|
{
|
|
return $this->belongsTo(City::class);
|
|
}
|
|
}
|