added customer and vendor scopes

This commit is contained in:
denisdulici
2020-04-07 14:39:35 +03:00
parent d94bf5d5b5
commit a2b17eaab5
9 changed files with 50 additions and 37 deletions

View File

@ -4,13 +4,14 @@ namespace App\Models\Common;
use App\Abstracts\Model;
use Bkwld\Cloner\Cloneable;
use App\Traits\Contacts;
use App\Traits\Currencies;
use App\Traits\Media;
use Illuminate\Notifications\Notifiable;
class Contact extends Model
{
use Cloneable, Currencies, Media, Notifiable;
use Cloneable, Contacts, Currencies, Media, Notifiable;
protected $table = 'contacts';
@ -79,6 +80,28 @@ class Contact extends Model
return $query->whereIn($this->table . '.type', (array) $types);
}
/**
* Scope to include only vendors.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeVendor($query)
{
return $query->whereIn($this->table . '.type', (array) $this->getVendorTypes());
}
/**
* Scope to include only customers.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCustomer($query)
{
return $query->whereIn($this->table . '.type', (array) $this->getCustomerTypes());
}
public function scopeEmail($query, $email)
{
return $query->where('email', '=', $email);