Actualizacion de Diseño Logins y Parte de Registro Negocios
This commit is contained in:
49
desarrollo/app/Models/Category.php
Normal file
49
desarrollo/app/Models/Category.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
protected $with = ['category_translations'];
|
||||
|
||||
public function getTranslation($field = '', $lang = false){
|
||||
$lang = $lang == false ? App::getLocale() : $lang;
|
||||
$category_translation = $this->category_translations->where('lang', $lang)->first();
|
||||
return $category_translation != null ? $category_translation->$field : $this->$field;
|
||||
}
|
||||
|
||||
public function category_translations(){
|
||||
return $this->hasMany(CategoryTranslation::class);
|
||||
}
|
||||
|
||||
public function products(){
|
||||
return $this->hasMany(Product::class);
|
||||
}
|
||||
|
||||
public function classified_products(){
|
||||
return $this->hasMany(CustomerProduct::class);
|
||||
}
|
||||
|
||||
public function categories()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function childrenCategories()
|
||||
{
|
||||
return $this->hasMany(Category::class, 'parent_id')->with('categories');
|
||||
}
|
||||
|
||||
public function parentCategory()
|
||||
{
|
||||
return $this->belongsTo(Category::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function attributes()
|
||||
{
|
||||
return $this->belongsToMany(Attribute::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user