JFIF x x C C " } !1AQa "q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w !1AQ aq"2B #3Rbr{
File "Category.php"
Full Path: /home/u703019046/domains/nawabs.com.au/public_html/app/Models/Category.php
File size: 1.38 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace App\Models;
use Session;
use App\Models\Product;
use App\Models\subcategory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Category extends Model
{
use HasFactory;
protected $table = 'categories';
protected $fillable = [
'slug',
'status',
'image'
];
public function Category()
{
return $this->hasMany(subcategory::class,'category_id','id');
}
public function translate_category()
{
return $this->belongsTo(TranslateCategory::class,'id','category_id')->where('lang_code','en');
}
public function translate_category_lang()
{
if(Session::get('front_lang')){
$lang_code = Session::get('front_lang');
}
else{
$lang_key = \App\Models\Setting::where('id', 1)->value('lang_key');
$lang_code = $lang_key ?? 'en';
}
return $this->belongsTo(TranslateCategory::class,'id','category_id')->where('lang_code', $lang_code);
}
protected $appends = ['name'];
protected $hidden = ['translate_category_lang'];
public function getNameAttribute()
{
return $this->translate_category_lang->name;
}
public function products()
{
return $this->hasMany(Product::class);
}
}