diff --git a/app/Models/Account.php b/app/Models/Account.php index a9ec862e24..8d659a27fd 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -150,6 +150,15 @@ class Account extends Model return $this->belongsTo(AccountType::class); } + /** + * @codeCoverageIgnore + * @return MorphMany + */ + public function locations(): MorphMany + { + return $this->morphMany(Location::class, 'locatable'); + } + /** * Get the account number. * diff --git a/app/Models/Location.php b/app/Models/Location.php new file mode 100644 index 0000000000..34dffc2da0 --- /dev/null +++ b/app/Models/Location.php @@ -0,0 +1,73 @@ +. + */ + +namespace FireflyIII\Models; + + +use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Database\Eloquent\Relations\MorphTo; + +/** + * Class Location + */ +class Location extends Model +{ + + /** + * The attributes that should be casted to native types. + * + * @var array + */ + protected $casts + = [ + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + 'deleted_at' => 'datetime', + 'zoomLevel' => 'int', + 'latitude' => 'float', + 'longitude' => 'float', + ]; + /** @var array Fields that can be filled */ + protected $fillable = ['locatable_id', 'locatable_type', 'latitude', 'longitude', 'zoom_level']; + + /** + * @codeCoverageIgnore + * Get all of the accounts. + */ + public function accounts(): MorphMany + { + return $this->morphMany(Account::class, 'noteable'); + } + + /** + * Get all of the owning attachable models. + * + * @codeCoverageIgnore + * + * @return MorphTo + */ + public function locatable(): MorphTo + { + return $this->morphTo(); + } + +} diff --git a/database/migrations/2019_12_28_191351_make_locations_table.php b/database/migrations/2019_12_28_191351_make_locations_table.php new file mode 100644 index 0000000000..8e077e99eb --- /dev/null +++ b/database/migrations/2019_12_28_191351_make_locations_table.php @@ -0,0 +1,45 @@ +bigIncrements('id'); + $table->timestamps(); + $table->softDeletes(); + + $table->integer('locatable_id', false, true); + $table->string('locatable_type', 255); + + $table->decimal('latitude', 24, 12)->nullable(); + $table->decimal('longitude', 24, 12)->nullable(); + $table->smallInteger('zoom_level', false, true)->nullable(); + } + ); + } +}