use ForestAdmin\LaravelForestAdmin\Services\Concerns\ForestCollection;
use ForestAdmin\LaravelForestAdmin\Services\SmartFeatures\SmartField;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
public function company(): SmartField
return $this->smartField(['type' => 'String'])
$company = Company::whereHas('departments', fn($query) => $query->where('departments.id', $this->department->id))->first();
function (Builder $query, $value, string $operator, string $aggregator) {
->whereIn('users.id', function ($q) use ($value, $aggregator) {
->join('departments', 'departments.company_id', '=', 'companies.id')
->join('users', 'users.department_id', '=', 'departments.id')
->whereRaw("LOWER (companies.name) LIKE LOWER(?)", ['%' . $value . '%'], $aggregator);
throw new ForestException(
"Unsupported operator: $operator"
public function department(): BelongsTo
return $this->belongsTo(Department::class);