1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Models\Store;
7
8use App\Models\Country;
9use App\Models\User;
10
11/**
12 * @property int $address_id
13 * @property string|null $city
14 * @property Country $country
15 * @property string|null $country_code
16 * @property \Carbon\Carbon $created_at
17 * @property \Carbon\Carbon|null $deleted_at
18 * @property string|null $first_name
19 * @property string|null $last_name
20 * @property string|null $phone
21 * @property string|null $state
22 * @property string|null $street
23 * @property \Carbon\Carbon|null $updated_at
24 * @property User $user
25 * @property int|null $user_id
26 * @property string|null $zip
27 */
28class Address extends Model
29{
30 protected $primaryKey = 'address_id';
31
32 public function user()
33 {
34 return $this->belongsTo(User::class, 'user_id');
35 }
36
37 public function country()
38 {
39 return $this->belongsTo(Country::class, 'country_code');
40 }
41
42 public function shippingRate()
43 {
44 if ($this->country === null) {
45 return 0;
46 } else {
47 return $this->country->shipping_rate;
48 }
49 }
50
51 public function countryName()
52 {
53 if ($this->country !== null) {
54 return $this->country->name;
55 }
56 }
57}