f1d196f018
- spatie/laravel-medialibrary instalat (migration media table)
- filament/spatie-laravel-media-library-plugin
- Company implements HasMedia + InteractsWithMedia
- collections: 'logo' + 'favicon' (singleFile)
- getLogoUrl() / getFaviconUrl() helpers
- Settings page extins: secțiune Logo & favicon cu FileUpload
- On save: clear collection + addMedia from temp upload + cleanup tmp file
- TenantPanelProvider render hooks:
- HEAD_END: theme-color meta + favicon + CSS vars override
(--primary-50 → --primary-950 generate din hex theme_color)
- SIDEBAR_LOGO_BEFORE: afișare logo upload-uit, max-height 56px
Cum funcționează:
- Tenant uploadează logo în Settings
- La fiecare request, render hook injectează <style> cu CSS vars custom
- Filament respectă --primary-* → toate butoanele/badge-urile primesc culoarea brand
- Logo apare deasupra meniului (sidebar)
100 lines
2.6 KiB
PHP
100 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Central;
|
|
|
|
use App\Models\Tenant\User;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
|
use Stancl\Tenancy\Database\Models\Tenant as BaseTenant;
|
|
|
|
/**
|
|
* Tenant model — extends Stancl Tenant for compatibility with the package
|
|
* (so we can use stancl helpers later if we want to switch to multi-DB).
|
|
*
|
|
* In single-DB mode we don't use HasDatabase. Domain identification is
|
|
* handled by our own ResolveTenant middleware (slug-based, not DNS records).
|
|
*/
|
|
class Company extends BaseTenant implements HasMedia
|
|
{
|
|
use InteractsWithMedia, SoftDeletes;
|
|
|
|
protected $table = 'companies';
|
|
|
|
public $incrementing = true;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'settings' => 'array',
|
|
'data' => 'array',
|
|
'trial_ends_at' => 'datetime',
|
|
'active_until' => 'datetime',
|
|
];
|
|
|
|
/** Stancl expects this to know what columns are NOT in the JSON `data` blob. */
|
|
public static function getCustomColumns(): array
|
|
{
|
|
return [
|
|
'id',
|
|
'slug', 'name', 'display_name', 'city', 'phone', 'email', 'contact_name',
|
|
'status', 'plan_id',
|
|
'trial_ends_at', 'active_until',
|
|
'settings',
|
|
'created_at', 'updated_at', 'deleted_at',
|
|
];
|
|
}
|
|
|
|
public function plan()
|
|
{
|
|
return $this->belongsTo(Plan::class);
|
|
}
|
|
|
|
public function users()
|
|
{
|
|
return $this->hasMany(User::class);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return in_array($this->status, ['active', 'trial'], true);
|
|
}
|
|
|
|
public function isAccessible(): bool
|
|
{
|
|
if ($this->status === 'archived' || $this->status === 'suspended') {
|
|
return false;
|
|
}
|
|
if ($this->status === 'expired') {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/** Get the URL for this tenant. */
|
|
public function url(?string $path = '/'): string
|
|
{
|
|
$central = config('app.central_domain') ?: 'service.mir.md';
|
|
return "https://{$this->slug}.{$central}{$path}";
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection('logo')->singleFile();
|
|
$this->addMediaCollection('favicon')->singleFile();
|
|
}
|
|
|
|
public function getLogoUrl(): ?string
|
|
{
|
|
$m = $this->getFirstMedia('logo');
|
|
return $m ? $m->getUrl() : null;
|
|
}
|
|
|
|
public function getFaviconUrl(): ?string
|
|
{
|
|
$m = $this->getFirstMedia('favicon');
|
|
return $m ? $m->getUrl() : null;
|
|
}
|
|
}
|