This commit is contained in:
Kevin Adametz 2024-08-05 12:05:24 +02:00
parent 04d677d37a
commit bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions

View file

@ -30,16 +30,14 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Shipping whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\ShippingPrice[] $shipping_prices
* @property-read int|null $shipping_prices_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\TransShipping> $translations
* @property-read int|null $translations_count
* @mixin \Eloquent
*/
class Shipping extends Model
{
protected $table = 'shippings';
protected $casts = [
'trans_name' => 'array',
];
protected $fillable = [
'name', 'active', 'free'
];
@ -78,4 +76,25 @@ class Shipping extends Model
public function shipping_prices(){
return $this->hasMany('App\Models\ShippingPrice', 'shipping_id', 'id');
}
public function translations()
{
return $this->hasMany(TransShipping::class, 'shipping_id');
}
public function getLang($key)
{
$lang = \App::getLocale();
if ($lang == 'de') {
return $this->{$key};
}
$trans = $this->getTrans($key, $lang);
return $trans != '' ? $trans : $this->{$key};
}
public function getTrans($key, $lang)
{
$trans = $this->translations->where('language','=', $lang)->where('key', $key)->first();
return $trans ? $trans->value : '';
}
}