wip
This commit is contained in:
40
app/Models/System/Settings/Location/Province.php
Normal file
40
app/Models/System/Settings/Location/Province.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System\Settings\Location;
|
||||
|
||||
use App\Models\Post\PostBranch;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
class Province extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'region',
|
||||
'name',
|
||||
];
|
||||
|
||||
/**
|
||||
* Translatable fields
|
||||
*
|
||||
* @var array<string>
|
||||
*/
|
||||
public $translatable = ['name'];
|
||||
|
||||
/**
|
||||
* Post branches
|
||||
*/
|
||||
public function postBranches(): HasMany
|
||||
{
|
||||
return $this->hasMany(PostBranch::class);
|
||||
}
|
||||
}
|
||||
73
app/Models/System/Settings/Location/Region.php
Normal file
73
app/Models/System/Settings/Location/Region.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System\Settings\Location;
|
||||
|
||||
class Region
|
||||
{
|
||||
/**
|
||||
* Mary
|
||||
*/
|
||||
public const MR = 'mr';
|
||||
|
||||
/**
|
||||
* Aşgabat
|
||||
*/
|
||||
public const AG = 'ag';
|
||||
|
||||
/**
|
||||
* Arkadag
|
||||
*/
|
||||
public const AK = 'ak';
|
||||
|
||||
/**
|
||||
* Ahal
|
||||
*/
|
||||
public const AH = 'ah';
|
||||
|
||||
/**
|
||||
* Lebap
|
||||
*/
|
||||
public const LB = 'lb';
|
||||
|
||||
/**
|
||||
* Balkan
|
||||
*/
|
||||
public const BN = 'bn';
|
||||
|
||||
/**
|
||||
* Daşoguz
|
||||
*/
|
||||
public const DZ = 'dz';
|
||||
|
||||
/**
|
||||
* Regions
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return [
|
||||
self::AG => __('Ashgabat'),
|
||||
self::AK => __('Arkadag'),
|
||||
self::MR => __('Mary'),
|
||||
self::AH => __('Ahal'),
|
||||
self::LB => __('Lebap'),
|
||||
self::BN => __('Balkan'),
|
||||
self::DZ => __('Dashoguz'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default value
|
||||
*/
|
||||
public static function default(): string
|
||||
{
|
||||
return self::AG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Label for given region
|
||||
*/
|
||||
public static function labelFor(string $region): string
|
||||
{
|
||||
return static::values()[$region] ?? '';
|
||||
}
|
||||
}
|
||||
73
app/Models/System/Settings/Location/UserAddress.php
Normal file
73
app/Models/System/Settings/Location/UserAddress.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\System\Settings\Location;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserAddress extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'last_name',
|
||||
'first_name',
|
||||
'company_name',
|
||||
'street_address',
|
||||
'street_address_plus',
|
||||
'zipcode',
|
||||
'city',
|
||||
'phone_number',
|
||||
'is_default',
|
||||
'type',
|
||||
'user_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* The dynamic attributes from mutators that should be returned with the user object.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = [
|
||||
'full_name',
|
||||
];
|
||||
|
||||
/**
|
||||
* Define if an address is default or not.
|
||||
*/
|
||||
public function isDefault(): bool
|
||||
{
|
||||
return $this->is_default === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* User
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap the model and its traits.
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($address) {
|
||||
if ($address->is_default) {
|
||||
$address->user->addresses()->where('type', $address->type)->update([
|
||||
'is_default' => false,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user