-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new model and related migrations for issues table
- Loading branch information
1 parent
c74c046
commit f5f58d8
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
database/migrations/2024_12_13_140033_create_issues_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_12_13_150749_add_has_issue_column_to_molecules_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
}); | ||
} | ||
}; |
31 changes: 31 additions & 0 deletions
31
database/migrations/2024_12_13_233712_create_issue_molecule_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |