pingcrm/app/Models/Organization.php

29 lines
697 B
PHP
Raw Normal View History

2019-03-18 08:53:00 -03:00
<?php
2020-09-08 19:45:49 -03:00
namespace App\Models;
2019-03-18 08:53:00 -03:00
use Illuminate\Database\Eloquent\SoftDeletes;
class Organization extends Model
{
use SoftDeletes;
public function contacts()
{
return $this->hasMany(Contact::class);
}
public function scopeFilter($query, array $filters)
{
$query->when($filters['search'] ?? null, function ($query, $search) {
$query->where('name', 'like', '%'.$search.'%');
2019-03-18 08:53:00 -03:00
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
if ($trashed === 'with') {
$query->withTrashed();
} elseif ($trashed === 'only') {
$query->onlyTrashed();
}
});
}
}