Change DB tables (remove temperature) (add sensors and readings Models Controllers and migrations) (and respect reallationships)
This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Temperature extends Model
|
||||
class Reading extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -15,9 +15,12 @@ class Temperature extends Model
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'temperature',
|
||||
'sensor_status',
|
||||
'longitude',
|
||||
'latitude',
|
||||
'type',
|
||||
'value',
|
||||
];
|
||||
|
||||
public function sensor()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Sensor');
|
||||
}
|
||||
}
|
32
app/Models/Sensor.php
Normal file
32
app/Models/Sensor.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Sensor extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'status',
|
||||
'longitude',
|
||||
'latitude',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\User');
|
||||
}
|
||||
|
||||
public function readings()
|
||||
{
|
||||
return $this->hasMany('App\Models\Reading');
|
||||
}
|
||||
}
|
@@ -37,4 +37,9 @@ class User extends Authenticatable
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function sensors()
|
||||
{
|
||||
return $this->hasMany('App\Models\Sensor');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user