Files
opensem/app/Models/Shop/Tariff.php
Ludovic CANDELLIER 63c6671c97 fixes
2021-11-07 19:58:38 +01:00

57 lines
1.4 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Kirschbaum\PowerJoins\PowerJoins;
use App\Traits\Model\HasComments;
class Tariff extends Model
{
use HasComments, HasRelationships, PowerJoins;
protected $guarded = ['id'];
protected $table = 'shop_tariffs';
public function sale_channel()
{
return $this->belongsTo(SaleChannel::class);
}
public function sale_channels()
{
// return $this->HasManyThrough(SaleChannel::class, PriceList::class);
return $this->HasManyThrough(SaleChannel::class, PriceList::class, 'id', 'id', 'id', 'sale_channel_id');
}
public function tariff_unity()
{
return $this->belongsTo(TariffUnity::class);
}
public function price_lists()
{
return $this->hasMany(PriceList::class);
}
public function scopeByAutocomplete($query, $str)
{
return $query->where($this->table . '.name', 'LIKE', "%${str}%")
->orWhere($this->table . '.ref', 'LIKE', "${str}%")
->orWhere($this->table . '.code', 'LIKE', "${str}%");
}
public function scopeBySaleChanel($query, $id)
{
return $query->where($this->table . '.sale_channel_id', $id);
}
public function scopeByStatus($query, $id)
{
return $query->where($this->table . '.status_id', $id);
}
}