mivita/dev/app-bak/Models/ShippingCountry.php
2025-10-20 17:42:08 +02:00

72 lines
2.4 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)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ShoppingOrder[] $shopping_orders
* @property-read int|null $shopping_orders_count
* @mixin \Eloquent
*/
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 function hasShoppingOrders()
{
return $this->shopping_orders()->exists();
}
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;
}
}