Skip to content

Commit

Permalink
feat: new model and related migrations for issues table
Browse files Browse the repository at this point in the history
  • Loading branch information
sriramkanakam87 committed Dec 13, 2024
1 parent c74c046 commit f5f58d8
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/Models/Issue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use OwenIt\Auditing\Contracts\Auditable;

class Issue extends Model implements Auditable
{
use \OwenIt\Auditing\Auditable;

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

/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
];

/**
* Get the molecules associated with the issue.
*/
public function molecules(): BelongsToMany
{
return $this->belongsToMany(Molecule::class)->withPivot('is_active', 'is_fixed')->withTimestamps();
}
}
30 changes: 30 additions & 0 deletions database/migrations/2024_12_13_140033_create_issues_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('issues', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id');
$table->longText('title');
$table->longText('comment');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('issues');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('molecules', function (Blueprint $table) {
$table->boolean('has_issues')->default(false);
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('molecules', function (Blueprint $table) {
$table->dropColumn(['has_issues']);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('issue_molecule', function (Blueprint $table) {
$table->id();
$table->foreignId('issue_id');
$table->foreignId('molecule_id');
$table->boolean('is_active')->default(true);
$table->boolean('is_fixed')->default(false);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('issue_molecule');
}
};

0 comments on commit f5f58d8

Please sign in to comment.