-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class City extends Model | ||
{ | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'name', | ||
]; | ||
|
||
/** | ||
* The attributes that should be hidden for arrays. | ||
* | ||
* @var array | ||
*/ | ||
protected $hidden = [ | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
/** | ||
* The attributes that should be casted to native types. | ||
* | ||
* @var array | ||
*/ | ||
protected $casts = [ | ||
'state_id' => 'integer', | ||
]; | ||
|
||
/** | ||
* Get the state that owns the city. | ||
*/ | ||
public function state() | ||
{ | ||
|
||
return $this->belongsTo(State::class, 'state_id'); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class State extends Model | ||
{ | ||
|
||
/** | ||
* The attributes that are mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $fillable = [ | ||
'name', | ||
'abbr', | ||
]; | ||
|
||
/** | ||
* The attributes that should be hidden for arrays. | ||
* | ||
* @var array | ||
*/ | ||
protected $hidden = [ | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
/** | ||
* Get all of the cities for the state. | ||
*/ | ||
public function city() | ||
{ | ||
|
||
return $this->hasMany(City::class); | ||
|
||
} | ||
|
||
} |