Skip to content

Commit

Permalink
- add location factory
Browse files Browse the repository at this point in the history
- move location migration to this plugin
- update service provider to run migrations
- update composer
  • Loading branch information
joshtorres committed Dec 23, 2023
1 parent c2899cd commit cb205de
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 20 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"illuminate/contracts": "^10.0",
"illuminate/database": "^10.0",
"illuminate/support": "^10.0",
"spatie/laravel-package-tools": "^1.15.0"
"spatie/laravel-package-tools": "^1.15.0",
"squirephp/countries-en": "^3.4"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
28 changes: 28 additions & 0 deletions database/factories/LocationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace OmniaDigital\CatalystLocation\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
use OmniaDigital\CatalystLocation\Models\Location;

class LocationFactory extends Factory
{
protected $model = Location::class;

public function definition(): array
{
return [
'address' => $this->faker->streetAddress(),
'address_line_2' => null,
'city' => $this->faker->city(),
'state' => $this->faker->state(),
'postal_code' => $this->faker->postcode(),
'country' => $this->faker->countryCode(),
'lat' => $this->faker->latitude(),
'lng' => $this->faker->longitude(),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
];
}
}
34 changes: 34 additions & 0 deletions database/migrations/2022_05_07_160700_create_locations_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

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

return new class extends Migration
{
public function up()
{
if (Schema::hasTable('locations')) {
return;
}
Schema::create('locations', function (Blueprint $table) {
$table->id();
$table->morphs('model');
$table->string('name')->nullable();
$table->string('address');
$table->string('address_line_2')->nullable();
$table->string('city');
$table->string('state');
$table->string('postal_code');
$table->string('country');
$table->string('lat')->nullable();
$table->string('lng')->nullable();
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('team_locations');
}
};
19 changes: 0 additions & 19 deletions database/migrations/create_catalyst_location_plugin_table.php.stub

This file was deleted.

2 changes: 2 additions & 0 deletions src/CatalystLocationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function packageBooted(): void
}
}

$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');

// Testing
Testable::mixin(new TestsCatalystLocation());
}
Expand Down
16 changes: 16 additions & 0 deletions src/Models/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,29 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use OmniaDigital\CatalystLocation\Database\Factories\LocationFactory;

class Location extends Model
{
use HasFactory;

protected $fillable = [
'name',
'address',
'address_line_2',
'city',
'state',
'postal_code',
'country',
'lat',
'lng',
];
protected $guarded = [];

protected static function newFactory()
{
return app(LocationFactory::class);
}
public function name(): Attribute
{
return new Attribute(
Expand Down

0 comments on commit cb205de

Please sign in to comment.