File: D:/HostingSpaces/SBogers10/blije-gasten.komma.pro/app/Komma/Addresses/Models/Address.php
<?php
namespace App\Komma\Addresses\Models;
use App\Komma\Company\Models\Company;
use App\Komma\Users\Models\KmsUser;
use App\Komma\Users\Models\SiteUser;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
/**
* Class Address
*
* @package App\Komma\Users\Models
* @property int $id
* @property string $street
* @property string $house_number
* @property string $postal_code
* @property string $city
* @property string $telephone
* @property string $country_iso2
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Company\Models\Company[] $company
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Users\Models\KmsUser[] $users
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereCity($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereCountry($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereHouseNumber($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address wherePostalCode($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereStreet($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereTelephone($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Addresses\Models\Address whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Address extends Model
{
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'street',
'house_number',
'postal_code',
'city',
'country_iso2',
];
protected static $addressRules = [
'street' => 'string|min:2|max:255',
'house_number' => 'string|min:1|max:255',
'postal_code' => 'string|min:2|max:255',
'city' => 'string|min:2|max:255',
];
/**
* Returns the site users this address belongs to
*
* @return MorphToMany
*/
public function siteUsers(): MorphToMany
{
return $this->morphedByMany(SiteUser::class, 'addressable');
}
/**
* Returns the kms users this address belongs to
*
* @return MorphToMany
*/
public function kmsUsers(): MorphToMany
{
return $this->morphedByMany(KmsUser::class, 'addressable');
}
/**
* Returns the companies this address belongs to
*
* @return BelongsToMany
*/
public function company(): BelongsToMany
{
return $this->belongsToMany(Company::class);
}
/**
* Returns the rule that is required for a address field
*
* @param string $rule
* @return mixed
*/
public static function getValidationRules(string $rule)
{
return self::$addressRules[$rule];
}
}