Why are you checking against verified everywhere when you only need it when the user tries to delete the technology?
Preventing pivot record from being deleted
I'm trying to verify technologies for profiles i do this manually from the admin panel, also users can add or remove technologies, BUT if the technology is already verified they shouldn't be able to remove it.
What im doing righ now is to have two different relationships "technologies" and "verifiedTechnologies"
public function technologies(): BelongsToMany
{
return $this->belongsToMany(Technology::class)
->using(ProfileTechnology::class)
->withTimestamps()
->wherePivot('verified', false)
->withPivot(['type', 'verified']);
}
public function verifiedTechnologies(): BelongsToMany
{
return $this->belongsToMany(Technology::class)
->using(ProfileTechnology::class)
->withTimestamps()
->wherePivot('verified', true)
->withPivot(['type', 'verified']);
}
public function allTechnologies()
{
return $this->verifiedTechnologies->concat($this->technologies);
}
i don't like this approach for a couple reasons, first of all when i need to present the technologies i need to concat both collections, when i'm trying to eager load i always need to eager load both, on nova if i'm presenting the relationship (i guess you can customize the query) but i need to create two relationship's, etc.
profile
id - integer
technology
id - integer
profile_technology
id - integer
profile_id - integer
technology_id - integer
verified - boolean
Any ideas how would you approach something like this?
Please or to participate in this conversation.