Skip to content

Commit

Permalink
feat: created the models and added relationships for the reporting fu…
Browse files Browse the repository at this point in the history
…nctionality
  • Loading branch information
sriramkanakam87 committed Apr 14, 2024
1 parent a0c6ddd commit b4f4b77
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/Models/Citation.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ public function molecules(): MorphToMany
{
return $this->morphedByMany(Molecule::class, 'citable');
}

/**
* Get all of the citations for the report.
*/
public function reports(): MorphToMany
{
return $this->morphToMany(Report::class, 'reportable');
}
}
8 changes: 8 additions & 0 deletions app/Models/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ public function molecules(): BelongsToMany
{
return $this->belongsToMany(Molecule::class);
}

/**
* Get all of the reports for the collection.
*/
public function reports(): MorphToMany
{
return $this->morphToMany(Report::class, 'reportable');
}
}
8 changes: 8 additions & 0 deletions app/Models/Molecule.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@ public function collections(): BelongsToMany
{
return $this->belongsToMany(Collection::class);
}

/**
* Get all of the reports for the molecule.
*/
public function reports(): MorphToMany
{
return $this->morphToMany(Report::class, 'reportable');
}
}
65 changes: 65 additions & 0 deletions app/Models/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use OwenIt\Auditing\Contracts\Auditable;

class Report extends Model implements Auditable
{
use HasFactory;
use \OwenIt\Auditing\Auditable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'title',
'evidence',
'url',
'status',
'comment',

];

/**
* Get all of the collections that are assigned this report.
*/
public function collections(): MorphToMany
{
return $this->morphedByMany(Collection::class, 'reportable');
}

/**
* Get all of the molecules that are assigned this repot.
*/
public function molecules(): MorphToMany
{
return $this->morphedByMany(Molecule::class, 'reportable');
}

/**
* Get all of the citations that are assigned this report.
*/
public function citations(): MorphToMany
{
return $this->morphedByMany(Citation::class, 'reportable');
}

/**
* Get all of the users that are assigned this report.
*/
public function users(): MorphToMany
{
return $this->morphedByMany(User::class, 'reportable');
}

}
8 changes: 8 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ class User extends Authenticatable implements Auditable
protected $appends = [
'profile_photo_url',
];

/**
* Get all of the reports for the user.
*/
public function reports(): MorphToMany
{
return $this->morphToMany(Report::class, 'reportable');
}
}

0 comments on commit b4f4b77

Please sign in to comment.