initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = ['disease_id', 'user_id', 'content', 'parent_id', 'status'];
|
||||
|
||||
public function disease()
|
||||
{
|
||||
return $this->belongsTo(Disease::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function replies()
|
||||
{
|
||||
return $this->hasMany(Comment::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function parent()
|
||||
{
|
||||
return $this->belongsTo(Comment::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function getContentWithPlaceholderAttribute()
|
||||
{
|
||||
return $this->status === 'deleted' ? 'Deleted Comment' : $this->content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Disease extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'deskripsi',
|
||||
'visibilitas',
|
||||
'schema',
|
||||
'cover_page'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'schema' => 'json'
|
||||
];
|
||||
|
||||
public function operators()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'disease_operator', 'disease_id', 'user_id');
|
||||
}
|
||||
|
||||
public function diseaseRecords()
|
||||
{
|
||||
return $this->hasMany(DiseaseRecord::class);
|
||||
}
|
||||
|
||||
protected function getCoverPageUrlAttribute(): ?string
|
||||
{
|
||||
if ($this->cover_page) {
|
||||
//$domain = env('APP_URL');
|
||||
return Storage::url('public/' . $this->cover_page);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function getExportUrlAttribute(): string
|
||||
{
|
||||
return url("/api/diseases/{$this->id}/export");
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$array = parent::toArray();
|
||||
$array['cover_page_url'] = $this->cover_page_url;
|
||||
$array['export_url'] = $this->export_url;
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DiseaseRecord extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['disease_id', 'data'];
|
||||
|
||||
protected $casts = [
|
||||
'data' => 'json',
|
||||
];
|
||||
|
||||
public function disease()
|
||||
{
|
||||
return $this->belongsTo(Disease::class);
|
||||
}
|
||||
|
||||
protected function getExportUrlAttribute(): string
|
||||
{
|
||||
return url("/api/diseases/{$this->disease_id}/records/{$this->id}/export");
|
||||
}
|
||||
|
||||
protected function getPublicFileUrl($path): string
|
||||
{
|
||||
if (empty($path)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return url("/storage/public/{$path}");
|
||||
}
|
||||
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
$array = parent::toArray();
|
||||
$array['export_url'] = $this->export_url;
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Log extends Model
|
||||
{
|
||||
protected $fillable = ['user_id', 'action', 'model', 'model_id', 'changes', 'description', 'is_success', 'timestamp'];
|
||||
|
||||
/**
|
||||
* Relationship with User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically resolve the related model instance
|
||||
*/
|
||||
public function relatedModel()
|
||||
{
|
||||
if (!class_exists($this->model)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->model::find($this->model_id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'institution',
|
||||
'gender',
|
||||
'phone_number',
|
||||
'tujuan_permohonan',
|
||||
'role',
|
||||
'approval_status',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $appends = ['managed_diseases'];
|
||||
|
||||
public function managedDiseases()
|
||||
{
|
||||
return $this->belongsToMany(Disease::class, 'disease_operator', 'user_id', 'disease_id');
|
||||
}
|
||||
|
||||
public function getManagedDiseasesAttribute()
|
||||
{
|
||||
if ($this->role === 'operator') {
|
||||
|
||||
$disease = $this->managedDiseases()
|
||||
->select(['diseases.id as disease_id', 'diseases.name'])
|
||||
->first();
|
||||
|
||||
if ($disease) {
|
||||
return [
|
||||
'disease_id' => $disease->disease_id,
|
||||
'name' => $disease->name,
|
||||
'pivot' => [
|
||||
'user_id' => $disease->pivot->user_id,
|
||||
'disease_id' => $disease->pivot->disease_id,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user