29 lines
691 B
PHP
29 lines
691 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
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', 'ilike', '%'.$search.'%');
|
|
})->when($filters['trashed'] ?? null, function ($query, $trashed) {
|
|
if ($trashed === 'with') {
|
|
$query->withTrashed();
|
|
} elseif ($trashed === 'only') {
|
|
$query->onlyTrashed();
|
|
}
|
|
});
|
|
}
|
|
}
|