-
Notifications
You must be signed in to change notification settings - Fork 97
/
City.php
61 lines (52 loc) · 1.13 KB
/
City.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php namespace October\Test\Models;
use Model;
/**
* City Model
*/
class City extends Model
{
use \October\Rain\Database\Traits\Validation;
/**
* @var string The database table used by the model.
*/
public $table = 'october_test_cities';
/*
* Disable timestamps by default.
* Remove this line if timestamps are defined in the database table.
*/
public $timestamps = false;
/**
* @var array fillable fields
*/
protected $fillable = ['custom_country_id', 'name'];
/**
* @var array rules
*/
public $rules = [
'country' => 'required'
];
/**
* @var array hasMany
*/
public $hasMany = [
'locations' => Location::class
];
/**
* @var array belongsTo
*/
public $belongsTo = [
'country' => [
Country::class,
'key' => 'custom_country_id'
],
];
/**
* scopeFilterCities
*/
public function scopeFilterCities($query, $model)
{
if ($countryId = $model->country_id) {
$query->where('custom_country_id', $countryId);
}
}
}