Commit 883a72b0 authored by Jacob Priddy's avatar Jacob Priddy 👌

create laravel override relationships

parent 4413c62e
......@@ -36,6 +36,14 @@ class Door extends Authenticatable
return $this->hasMany(Attempt::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function overrides(): HasMany
{
return $this->hasMany(Override::class);
}
public static function boot()
{
parent::boot();
......@@ -55,6 +63,12 @@ class Door extends Authenticatable
foreach ($door->attempts() as $attempt) {
$attempt->delete();
}
// Delete all overrides
/** @var \App\Override $override */
foreach ($door->overrides() as $override) {
$override->delete();
}
});
}
}
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Override extends Model
{
protected $dates = ['start', 'end'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function door(): BelongsTo
{
return $this->belongsTo(Door::class);
}
}
......@@ -12,14 +12,7 @@ class User extends Authenticatable
'*',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'expires_at' => 'datetime',
];
protected $dates = ['expires_at'];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
......@@ -45,6 +38,14 @@ class User extends Authenticatable
return $this->belongsToMany(Group::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function overrides(): HasMany
{
return $this->hasMany(Override::class);
}
public static function boot()
{
parent::boot();
......@@ -63,6 +64,11 @@ class User extends Authenticatable
foreach ($user->entries() as $entry) {
$entry->delete();
}
/** @var \App\Override $override */
foreach ($user->overrides() as $override) {
$override->delete();
}
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment