Initial: Laravel 13 setup with multi-tenant schema

This commit is contained in:
Jan (Plesk) 2026-04-20 00:34:21 +02:00
commit a78a50ef0c
69 changed files with 10805 additions and 0 deletions

View file

@ -0,0 +1,20 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
#[Signature('app:mqtt-listener')]
#[Description('Command description')]
class MqttListener extends Command
{
/**
* Execute the console command.
*/
public function handle()
{
//
}
}

View file

@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}

12
app/Models/AuditLog.php Normal file
View file

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class AuditLog extends Model {
protected $table = 'audit_log';
public $timestamps = false;
protected $fillable = ['user_id','device_id','action','old_value','new_value','ip_address','created_at'];
protected $casts = ['created_at'=>'datetime'];
public function user(): BelongsTo { return $this->belongsTo(User::class); }
public function device(): BelongsTo { return $this->belongsTo(Device::class); }
}

15
app/Models/Device.php Normal file
View file

@ -0,0 +1,15 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Device extends Model {
protected $fillable = ['tenant_id','name','slug','type','mqtt_topic_prefix','mqtt_username','timezone','settings','last_seen_at'];
protected $casts = ['settings'=>'array','last_seen_at'=>'datetime'];
public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
public function readings(): HasMany { return $this->hasMany(Reading::class); }
public function events(): HasMany { return $this->hasMany(Event::class); }
public function latestReading(string $metric) {
return $this->readings()->where('metric',$metric)->latest('recorded_at')->first();
}
}

10
app/Models/Event.php Normal file
View file

@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Event extends Model {
public $timestamps = false;
protected $fillable = ['device_id','event_type','severity','payload','occurred_at'];
protected $casts = ['payload'=>'array','occurred_at'=>'datetime'];
public function device(): BelongsTo { return $this->belongsTo(Device::class); }
}

12
app/Models/Reading.php Normal file
View file

@ -0,0 +1,12 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Reading extends Model {
public $timestamps = false;
protected $fillable = ['device_id','metric','value','value_text','recorded_at'];
protected $casts = ['value'=>'decimal:3','recorded_at'=>'datetime'];
public function device(): BelongsTo { return $this->belongsTo(Device::class); }
public function scopeMetric($q, string $metric) { return $q->where('metric',$metric); }
public function scopeSince($q, $ts) { return $q->where('recorded_at','>=',$ts); }
}

9
app/Models/Tenant.php Normal file
View file

@ -0,0 +1,9 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Tenant extends Model {
protected $fillable = ['name','slug','plan'];
public function users(): HasMany { return $this->hasMany(User::class); }
public function devices(): HasMany { return $this->hasMany(Device::class); }
}

19
app/Models/User.php Normal file
View file

@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
#[Fillable(['tenant_id','name','email','password','role'])]
#[Hidden(['password','remember_token'])]
class User extends Authenticatable {
use HasFactory, Notifiable;
protected function casts(): array {
return ['email_verified_at'=>'datetime','password'=>'hashed'];
}
public function tenant(): BelongsTo { return $this->belongsTo(Tenant::class); }
public function isAdmin(): bool { return $this->role === 'admin'; }
}

View file

@ -0,0 +1,24 @@
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
}