first commit
This commit is contained in:
34
app/Models/Traits/HasArea.php
Normal file
34
app/Models/Traits/HasArea.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use App\Models\ChinaArea;
|
||||
|
||||
trait HasArea
|
||||
{
|
||||
|
||||
public function province()
|
||||
{
|
||||
return $this->belongsTo(ChinaArea::class, 'province_id', 'code');
|
||||
}
|
||||
|
||||
public function city()
|
||||
{
|
||||
return $this->belongsTo(ChinaArea::class, 'city_id', 'code');
|
||||
}
|
||||
|
||||
public function area()
|
||||
{
|
||||
return $this->belongsTo(ChinaArea::class, 'area_id', 'code');
|
||||
}
|
||||
|
||||
public function getFullAddressAttribute()
|
||||
{
|
||||
$address = $this->province->name . ' ';
|
||||
$address .= $this->city->name . ' ';
|
||||
$address .= $this->area->name . ' ';
|
||||
$address .= $this->address;
|
||||
|
||||
return $address;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user