Skip to content

Commit

Permalink
Create timezone migration, model & factory #32
Browse files Browse the repository at this point in the history
  • Loading branch information
drewroberts committed Mar 4, 2021
1 parent 1f53664 commit c70f4f7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
23 changes: 23 additions & 0 deletions database/factories/TimezoneFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Tipoff\Addresses\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Tipoff\Addresses\Models\Timezone;

class TimezoneFactory extends Factory
{
protected $model = Timezone::class;

public function definition()
{
return [
'name' => $this->faker->timezone,
'title' => $this->faker->timezone,
'php' => $this->faker->timezone,
'is_daylight_saving' => $this->faker->boolean
];
}
}
22 changes: 22 additions & 0 deletions database/migrations/2014_01_01_100000_create_timezones_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTimezonesTable extends Migration
{
public function up()
{
Schema::create('timezones', function (Blueprint $table) {
$table->id();
$table->string('name')->unique(); // Abbreviation
$table->string('title')->unique();
$table->string('php')->unique(); // Supported PHP Timezone: https://www.php.net/manual/en/timezones.php
$table->boolean('is_daylight_saving')->default(1); // Just for reference, Carbon has this.
$table->decimal('dst', 4, 2)->nullable(); // Just for reference, Carbon has this.
$table->decimal('standard', 4, 2)->nullable(); // Just for reference, Carbon has this.
});
}
}
29 changes: 29 additions & 0 deletions src/Models/Timezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Tipoff\Addresses\Models;

use Tipoff\Support\Models\BaseModel;
use Tipoff\Support\Traits\HasCreator;
use Tipoff\Support\Traits\HasPackageFactory;
use Tipoff\Support\Traits\HasUpdater;

class Timezone extends BaseModel
{
use HasPackageFactory;
use HasCreator;
use HasUpdater;

public $timestamps = false;

public function markets()
{
return $this->belongsToMany(app('market'));
}

public function locations()
{
return $this->belongsToMany(app('location'));
}
}

0 comments on commit c70f4f7

Please sign in to comment.