Files
opensem/app/Models/Shop/Tariff.php
2021-11-01 18:37:25 +01:00

51 lines
1.2 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 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);
}
}