Skip to content

Commit

Permalink
Add models
Browse files Browse the repository at this point in the history
  • Loading branch information
magnobiet committed Feb 8, 2016
1 parent e394ccf commit 96803b4
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app/Models/City.php
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');

}

}
40 changes: 40 additions & 0 deletions app/Models/State.php
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);

}

}

0 comments on commit 96803b4

Please sign in to comment.