67 lines
2.3 KiB
PHP
67 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\ShippingCountry as ModelsShippingCountry;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* App\Models\ShippingCountry
|
|
*
|
|
* @property int $id
|
|
* @property int $shipping_id
|
|
* @property int|null $country_id
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\Country|null $country
|
|
* @property-read \App\Models\Shipping $shipping
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry whereCountryId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry whereShippingId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\ShippingCountry whereUpdatedAt($value)
|
|
* @mixin \Eloquent
|
|
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ShoppingOrder[] $shopping_orders
|
|
* @property-read int|null $shopping_orders_count
|
|
*/
|
|
class ShippingCountry extends Model
|
|
{
|
|
protected $table = 'shipping_countries';
|
|
|
|
|
|
protected $fillable = [
|
|
'shipping_id', 'country_id'
|
|
];
|
|
|
|
public function shipping()
|
|
{
|
|
return $this->belongsTo('App\Models\Shipping', 'shipping_id');
|
|
}
|
|
|
|
public function country()
|
|
{
|
|
return $this->belongsTo('App\Models\Country', 'country_id');
|
|
}
|
|
|
|
public function shopping_orders()
|
|
{
|
|
return $this->hasMany('App\Models\ShoppingOrder', 'country_id');
|
|
}
|
|
|
|
|
|
public static function getActiveShippingCountries(){
|
|
$ret = [];
|
|
$ShippingCountries = ShippingCountry::all();
|
|
foreach($ShippingCountries as $ShippingCountry){
|
|
if($ShippingCountry->shipping->active){
|
|
$ret[$ShippingCountry->country_id] = $ShippingCountry->country->getLocated();
|
|
}
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
|
|
}
|