Initial: Laravel 13 setup with multi-tenant schema
This commit is contained in:
commit
a78a50ef0c
69 changed files with 10805 additions and 0 deletions
15
app/Models/Device.php
Normal file
15
app/Models/Device.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue