fix on shelve with available offers

This commit is contained in:
Ludovic CANDELLIER
2022-04-25 21:59:53 +02:00
parent 328d791b87
commit c9bf18d87d
4 changed files with 68 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
class Categorizable extends Model
{
protected $table = 'categorizables';
public function categorizable()
{
return $this->morphTo();
}
public function category()
{
return $this->belongsTo(Category::class);
}
public function articles()
{
return $this->belongsTo(Article::class)->where('categorizable_type', Article::class);
}
public function scopeByCategory($query, $category_id)
{
return $query->where($this->table . '.category_id', $category_id);
}
public function scopeByCategories($query, $categories_id)
{
return $query->whereIn($this->table . '.category_id', $categories_id);
}
public function scopeByCategoryParent($query, $category_id)
{
$category = Category::find($category_id);
return $query->whereHas('category', function ($query) use ($category) {
return $query->inRange($category->_lft, $category->_rgt);
});
}
}