gruene-seele/app/Models/UserShop.php
2025-04-01 10:39:21 +02:00

132 lines
3.8 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use App\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class UserShop
*
* @property int $id
* @property int $user_id
* @property string|null $url
* @property string|null $name
* @property string|null $description
* @property string|null $about_you
* @property string|null $user_address
* @property string|null $trans
* @property bool $pick_up
* @property bool $active
* @property Carbon|null $active_date
* @property string|null $featured
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $deleted_at
* @property User $user
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|UserShop newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UserShop newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|UserShop onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|UserShop query()
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereAboutYou($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereActiveDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereFeatured($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop wherePickUp($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereTrans($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereUserAddress($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|UserShop withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|UserShop withoutTrashed()
* @mixin \Eloquent
*/
class UserShop extends Model
{
use SoftDeletes;
protected $table = 'user_shops';
protected $casts = [
'user_id' => 'int',
'pick_up' => 'bool',
'active' => 'bool',
'featured' => 'array',
'trans' => 'array',
];
protected $dates = [
'active_date'
];
protected $fillable = [
'user_id',
'url',
'name',
'description',
'about_you',
'user_address',
'trans',
'pick_up',
'active',
'active_date',
'featured'
];
public function user()
{
return $this->belongsTo(User::class);
}
public function getUrlPreview()
{
return $this->url ? config('app.shop_url')."/".$this->url : "";
}
public function getLang($key, $default = true)
{
$lang = \App::getLocale();
if ($lang == 'de') {
return $this->{$key};
}
return $this->getTrans($key, $lang, $default);
}
public function getTrans($key, $lang, $default = true)
{
if ($lang == 'de') {
return $this->{$key};
}
if(!empty($this->trans[$lang][$key])){
return $this->trans[$lang][$key];
}
if($default){
return !empty($this->{$key}) ? $this->{$key} : '';
}
return "";
}
public function isActive(){
if($this->active){
return true;
}
return false;
}
public function getSubdomain(){
return "";
}
}