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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user