FEATURE: add relationship methods to categories and content
This commit is contained in:
@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
use Modules\Categories\Entities\Category;
|
||||
|
||||
/**
|
||||
* Class Content
|
||||
@@ -407,6 +408,11 @@ class Content extends Model
|
||||
return $this->belongsToMany(File::class, 'contents_has_files');
|
||||
}
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save history entry into database
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
namespace Modules\Categories\Entities;
|
||||
|
||||
use App\Models\Content;
|
||||
use App\Models\Module;
|
||||
use Franzose\ClosureTable\Models\Entity;
|
||||
|
||||
@@ -12,9 +13,7 @@ class Category extends Entity implements CategoryInterface
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'categories';
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* ClosureTable model instance.
|
||||
*
|
||||
@@ -22,7 +21,13 @@ class Category extends Entity implements CategoryInterface
|
||||
*/
|
||||
protected $closure = 'Modules\Categories\Entities\CategoryClosure';
|
||||
|
||||
public function module() {
|
||||
public function module()
|
||||
{
|
||||
return $this->belongsTo(Module::class);
|
||||
}
|
||||
|
||||
public function content()
|
||||
{
|
||||
return $this->hasMany(Content::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user