Transformed into pivot models and Created ResumeSlotValue
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Policies\ResumePolicy;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -25,11 +26,15 @@ class Resume extends Model
|
||||
return $this->belongsTo(User::class, 'creator_id');
|
||||
}
|
||||
|
||||
public function slots(): HasMany
|
||||
{
|
||||
return $this->hasMany(ResumeSlot::class);
|
||||
}
|
||||
|
||||
public function components(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ResumeComponent::class, 'resume_resume_component')
|
||||
->withPivot('order', 'data')
|
||||
->withTimestamps()
|
||||
->orderBy('order');
|
||||
return $this->belongsToMany(ResumeComponent::class)
|
||||
->using(ResumeSlot::class)
|
||||
->orderBy('resume_slots.order');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Attributes\UsePolicy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[UsePolicy(ResumeComponentPolicy::class)]
|
||||
class ResumeComponent extends Model
|
||||
@@ -21,7 +22,24 @@ class ResumeComponent extends Model
|
||||
public function resumes(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Resume::class, 'resume_resume_component')
|
||||
->withPivot('order', 'data')
|
||||
->using(ResumeSlot::class)
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function slots(): HasMany
|
||||
{
|
||||
return $this->hasMany(ResumeSlot::class);
|
||||
}
|
||||
|
||||
public function inputs(): HasMany
|
||||
{
|
||||
return $this->hasMany(ResumeComponentInput::class);
|
||||
}
|
||||
|
||||
public function dataTypes(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ResumeComponentDataType::class)
|
||||
->using(ResumeComponentInput::class)
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ResumeComponentDataType extends Model
|
||||
{
|
||||
@@ -14,4 +16,16 @@ class ResumeComponentDataType extends Model
|
||||
'data_structure',
|
||||
'vue_component_name'
|
||||
];
|
||||
|
||||
public function inputs(): HasMany
|
||||
{
|
||||
return $this->hasMany(ResumeComponentInput::class);
|
||||
}
|
||||
|
||||
public function components(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ResumeComponent::class)
|
||||
->using(ResumeComponentInput::class)
|
||||
->withTimestamps();
|
||||
}
|
||||
}
|
||||
|
||||
39
app/Models/ResumeComponentInput.php
Normal file
39
app/Models/ResumeComponentInput.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Policies\ResumeComponentPolicy;
|
||||
use Illuminate\Database\Eloquent\Attributes\UsePolicy;
|
||||
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\Pivot;
|
||||
|
||||
class ResumeComponentInput extends Pivot
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ResumeComponentFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'resume_component_id',
|
||||
'resume_component_data_type_id',
|
||||
'name',
|
||||
'placeholder'
|
||||
];
|
||||
|
||||
public function resumes()
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
public function component(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ResumeComponent::class);
|
||||
}
|
||||
|
||||
public function dataType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ResumeComponentDataType::class);
|
||||
}
|
||||
}
|
||||
32
app/Models/ResumeSlot.php
Normal file
32
app/Models/ResumeSlot.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Policies\ResumeComponentPolicy;
|
||||
use Illuminate\Database\Eloquent\Attributes\UsePolicy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class ResumeSlot extends Pivot
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ResumeComponentFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'resume_id',
|
||||
'resume_component_id',
|
||||
'order',
|
||||
];
|
||||
|
||||
public function resume()
|
||||
{
|
||||
return $this->belongsTo(Resume::class);
|
||||
}
|
||||
|
||||
public function component()
|
||||
{
|
||||
return $this->belongsTo(ResumeComponent::class);
|
||||
}
|
||||
}
|
||||
51
app/Models/ResumeSlotValue.php
Normal file
51
app/Models/ResumeSlotValue.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Policies\ResumeComponentPolicy;
|
||||
use Illuminate\Database\Eloquent\Attributes\UsePolicy;
|
||||
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\Pivot;
|
||||
|
||||
class ResumeSlotValue extends Pivot
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\ResumeComponentFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'resume_slot_id',
|
||||
'resume_component_input_id',
|
||||
'value'
|
||||
];
|
||||
|
||||
public function resume(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Resume::class)
|
||||
->using(ResumeSlot::class);
|
||||
}
|
||||
|
||||
public function component(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ResumeComponent::class)
|
||||
->using(ResumeSlot::class);
|
||||
}
|
||||
|
||||
public function dataType(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ResumeComponentDataType::class)
|
||||
->using(ResumeComponentInput::class);
|
||||
}
|
||||
|
||||
public function slot(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ResumeSlot::class);
|
||||
}
|
||||
|
||||
public function componentInput(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ResumeComponentInput::class);
|
||||
}
|
||||
}
|
||||
23
database/factories/ResumeComponentInputFactory.php
Normal file
23
database/factories/ResumeComponentInputFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ResumeComponentInput>
|
||||
*/
|
||||
class ResumeComponentInputFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('resume_resume_component', function (Blueprint $table) {
|
||||
Schema::create('resume_slots', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignIdFor(Resume::class)->constrained()->onDelete('cascade');
|
||||
@@ -21,8 +21,6 @@ return new class extends Migration
|
||||
|
||||
$table->integer('order')->default(0);
|
||||
|
||||
$table->json('data')->comment('JSON structure to define the data for the resume component');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
@@ -32,6 +30,6 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('resume_resume_component_link');
|
||||
Schema::dropIfExists('resume_slots');
|
||||
}
|
||||
};
|
||||
@@ -14,7 +14,7 @@ return new class extends Migration
|
||||
Schema::create('resume_component_data_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->json('data_structure')->comment('JSON structure to define the data validation in laravel validation format (https://laravel.com/docs/12.x/validation#quick-writing-the-validation-logic)');
|
||||
$table->string('data_structure')->comment('valid format for the value in Laravel validation format (https://laravel.com/docs/12.x/validation#quick-writing-the-validation-logic)');
|
||||
$table->string('vue_component_name');
|
||||
|
||||
$table->timestamps();
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ResumeComponent;
|
||||
use App\Models\ResumeComponentDataType;
|
||||
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('resume_component_inputs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignIdFor(ResumeComponent::class)->constrained()->onDelete('cascade');
|
||||
$table->foreignIdFor(ResumeComponentDataType::class)->constrained()->onDelete('cascade');
|
||||
|
||||
$table->string('name');
|
||||
$table->string("placeholder");
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('resume_component_inputs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use App\Models\ResumeComponentInput;
|
||||
use App\Models\ResumeSlot;
|
||||
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('resume_slot_values', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->foreignIdFor(ResumeSlot::class);
|
||||
$table->foreignIdFor(ResumeComponentInput::class);
|
||||
|
||||
$table->string('value');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('resume_slot_value');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user