feat: add all Eloquent models with relationships
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Activity extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title', 'description', 'start_date', 'end_date',
|
||||
'created_by', 'status', 'approved_by', 'approved_at',
|
||||
'executed_at', 'execution_notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'approved_at' => 'datetime',
|
||||
'executed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function approver(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'approved_by');
|
||||
}
|
||||
|
||||
public function participants(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'activity_member');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ActivityLog extends Model
|
||||
{
|
||||
protected $fillable = ['user_id', 'action', 'model_type', 'model_id', 'description'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Approval extends Model
|
||||
{
|
||||
protected $fillable = ['model_type', 'model_id', 'required_approvals', 'status'];
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(ApprovalItem::class);
|
||||
}
|
||||
|
||||
public function approvable()
|
||||
{
|
||||
return $this->morphTo(__FUNCTION__, 'model_type', 'model_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ApprovalItem extends Model
|
||||
{
|
||||
protected $fillable = ['approval_id', 'user_id', 'decision', 'notes'];
|
||||
|
||||
public function approval(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Approval::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Audit extends Model
|
||||
{
|
||||
protected $fillable = ['auditor_id', 'model_type', 'model_id', 'issue_type', 'description', 'status'];
|
||||
|
||||
public function auditor(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'auditor_id');
|
||||
}
|
||||
|
||||
public function responses(): HasMany
|
||||
{
|
||||
return $this->hasMany(AuditResponse::class);
|
||||
}
|
||||
|
||||
public function auditable()
|
||||
{
|
||||
return $this->morphTo(__FUNCTION__, 'model_type', 'model_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class AuditResponse extends Model
|
||||
{
|
||||
protected $fillable = ['audit_id', 'responded_by', 'response_text'];
|
||||
|
||||
public function audit(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Audit::class);
|
||||
}
|
||||
|
||||
public function responder(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'responded_by');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class CashCategory extends Model
|
||||
{
|
||||
protected $fillable = ['name'];
|
||||
|
||||
public function records(): HasMany
|
||||
{
|
||||
return $this->hasMany(CashRecord::class, 'category_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CashRecord extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'amount', 'category_id', 'description',
|
||||
'date', 'created_by', 'verified_by', 'verified_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'date' => 'date',
|
||||
'verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CashCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function verifier(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'verified_by');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Division extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'description'];
|
||||
|
||||
public function members(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class MemberStatusLog extends Model
|
||||
{
|
||||
protected $fillable = ['member_id', 'changed_by', 'old_status', 'new_status', 'reason'];
|
||||
|
||||
public function member(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'member_id');
|
||||
}
|
||||
|
||||
public function changedBy(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'changed_by');
|
||||
}
|
||||
}
|
||||
+32
-12
@@ -2,32 +2,52 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
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\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
#[Fillable(['name', 'email', 'password'])]
|
||||
#[Hidden(['password', 'remember_token'])]
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use HasFactory, Notifiable, HasRoles;
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password',
|
||||
'phone', 'address', 'division_id',
|
||||
'status', 'inactive_reason', 'last_activity_date',
|
||||
];
|
||||
|
||||
protected $hidden = ['password', 'remember_token'];
|
||||
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'last_activity_date' => 'date',
|
||||
];
|
||||
|
||||
public function division(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Division::class);
|
||||
}
|
||||
|
||||
public function activities(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Activity::class, 'activity_member');
|
||||
}
|
||||
|
||||
public function statusLogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(MemberStatusLog::class, 'member_id');
|
||||
}
|
||||
|
||||
public function cashRecords(): HasMany
|
||||
{
|
||||
return $this->hasMany(CashRecord::class, 'created_by');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Vote extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title', 'description', 'type',
|
||||
'related_id', 'status', 'deadline', 'created_by',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'deadline' => 'datetime',
|
||||
];
|
||||
|
||||
public function creator(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(VoteItem::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class VoteItem extends Model
|
||||
{
|
||||
protected $fillable = ['vote_id', 'user_id', 'choice'];
|
||||
|
||||
public function vote(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Vote::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user