39 lines
957 B
PHP
39 lines
957 B
PHP
<?php
|
|
|
|
namespace App\Models\Shop;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Znck\Eloquent\Traits\BelongsToThrough;
|
|
|
|
class Unity extends Model
|
|
{
|
|
use BelongsToThrough, softDeletes;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $table = 'shop_unities';
|
|
|
|
public function package()
|
|
{
|
|
return $this->belongsTo(Package::class);
|
|
}
|
|
|
|
public function article_family()
|
|
{
|
|
return $this->belongsToThrough(ArticleNature::class, Package::class, null, '', ['App\Models\Shop\ArticleNature' => 'article_family_id', 'App\Models\Shop\Package' => 'package_id']);
|
|
}
|
|
|
|
public function scopeByPackage($query, $id)
|
|
{
|
|
return $query->where($this->table.'.package_id', $id);
|
|
}
|
|
|
|
public function scopeByArticleNature($query, $id)
|
|
{
|
|
return $query->whereHas('package', function ($query) use ($id) {
|
|
$query->byArticleNature($id);
|
|
});
|
|
}
|
|
}
|