This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from osinitiative/develop
Added Morph for Address, Phone and Email.
- Loading branch information
Showing
27 changed files
with
701 additions
and
19 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
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,27 @@ | ||
<?php | ||
|
||
namespace OSI\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Address extends Model | ||
{ | ||
protected $guarded = ['id']; | ||
|
||
/** | ||
* Get all of the owning addressable models. | ||
*/ | ||
public function addressable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
|
||
/** | ||
* Get Country | ||
* @return \OSI\Models\Country | ||
*/ | ||
public function country() | ||
{ | ||
return $this->belongsTo(Country::class); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace OSI\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Country extends Model | ||
{ | ||
protected $guarded = []; | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace OSI\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Email extends Model | ||
{ | ||
protected $guarded = ['id']; | ||
|
||
/** | ||
* Get all of the owning emailable models. | ||
*/ | ||
public function emailable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace OSI\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Phone extends Model | ||
{ | ||
protected $guarded = ['id']; | ||
|
||
/** | ||
* Get all of the owning phoneable models. | ||
*/ | ||
public function phoneable() | ||
{ | ||
return $this->morphTo(); | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace OSI\Models; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class PhoneType extends Model | ||
{ | ||
const HOME = 1; | ||
const MOBILE = 2; | ||
const OFFICE = 3; | ||
const OTHER = 4; | ||
} |
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
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
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
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,15 @@ | ||
<?php | ||
|
||
namespace OSI\Traits; | ||
|
||
use OSI\Traits\Morphs\Addressable; | ||
use OSI\Traits\Morphs\Emailable; | ||
use OSI\Traits\Morphs\Phoneable; | ||
|
||
/** | ||
* HasProfile Trait | ||
*/ | ||
trait HasProfile | ||
{ | ||
use Addressable, Emailable, Phoneable; | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace OSI\Traits\Morphs; | ||
|
||
/** | ||
* Addressable Trait | ||
*/ | ||
trait Addressable | ||
{ | ||
/** | ||
* Get all of the addresses | ||
*/ | ||
public function addresses() | ||
{ | ||
return $this->morphMany(\OSI\Models\Address::class, 'addressable'); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace OSI\Traits\Morphs; | ||
|
||
/** | ||
* Emailable Trait | ||
*/ | ||
trait Emailable | ||
{ | ||
/** | ||
* Get all of the emails. | ||
*/ | ||
public function emails() | ||
{ | ||
return $this->morphMany(\CLNQCDRS\Models\Email::class, 'emailable'); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace OSI\Traits\Morphs; | ||
|
||
/** | ||
* Phoneable Trait | ||
*/ | ||
trait Phoneable | ||
{ | ||
/** | ||
* Get all of the phones. | ||
*/ | ||
public function phones() | ||
{ | ||
return $this->morphMany(\OSI\Models\Phone::class, 'phoneable'); | ||
} | ||
} |
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
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,14 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\OSI\Models\Address::class, function (Faker $faker) { | ||
return [ | ||
'country_id' => $faker->randomElement(range(1, 200)), | ||
'primary' => $faker->streetName, | ||
'secondary' => $faker->streetAddress, | ||
'postcode' => $faker->postcode, | ||
'city' => $faker->city, | ||
'state' => $faker->state, | ||
]; | ||
}); |
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,9 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\OSI\Models\Email::class, function (Faker $faker) { | ||
return [ | ||
'email' => $faker->companyEmail, | ||
]; | ||
}); |
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,10 @@ | ||
<?php | ||
|
||
use Faker\Generator as Faker; | ||
|
||
$factory->define(\OSI\Models\Phone::class, function (Faker $faker) { | ||
return [ | ||
'phone_type_id' => $faker->randomElement([1, 2, 3, 4]), | ||
'phone_number' => $faker->phoneNumber, | ||
]; | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
database/migrations/2017_12_23_000005_create_countries_table.php
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,33 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateCountriesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('countries', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('code'); | ||
$table->label(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('countries'); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
database/migrations/2017_12_23_000009_create_phone_types_table.php
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,32 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreatePhoneTypesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('phone_types', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->label(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('phone_types'); | ||
} | ||
} |
Oops, something went wrong.