feat: Add dataChangeRequests morph relation to PartnerMedia, Company, and Journalist models, refactor CategoryNews relationships, and pluralize HasMany method names.
This commit is contained in:
parent
5968377f5d
commit
bdd508220b
@ -37,7 +37,7 @@ protected function company(Builder $query): void
|
||||
$query->where('type', AnnouncementType::COMPANY);
|
||||
}
|
||||
|
||||
public function announcementMedia(): HasMany
|
||||
public function announcementMedias(): HasMany
|
||||
{
|
||||
return $this->hasMany(AnnouncementMedia::class);
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Swindon\FilamentHashids\Traits\HasHashid;
|
||||
|
||||
class CategoryNews extends Model
|
||||
@ -12,13 +12,21 @@ class CategoryNews extends Model
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function category(): BelongsToMany
|
||||
protected function casts(): array
|
||||
{
|
||||
return $this->belongsToMany(Category::class);
|
||||
return [
|
||||
'category_id' => 'integer',
|
||||
'news_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function news(): BelongsToMany
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsToMany(News::class);
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function news(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(News::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@ -25,26 +26,6 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function journalists(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Journalist::class, PartnerMedia::class);
|
||||
}
|
||||
|
||||
public function partnerMedia(): HasOne
|
||||
{
|
||||
return $this->hasOne(PartnerMedia::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function verificationRequest(): HasOne
|
||||
{
|
||||
return $this->hasOne(VerificationRequest::class);
|
||||
}
|
||||
|
||||
public static function dataChangeEntryLabels(): array
|
||||
{
|
||||
return [
|
||||
@ -70,4 +51,29 @@ public static function dataChangeEntryLabels(): array
|
||||
'profile_docs' => 'Dokumen Profil Perusahaan',
|
||||
];
|
||||
}
|
||||
|
||||
public function dataChangeRequests(): MorphMany
|
||||
{
|
||||
return $this->morphMany(DataChangeRequest::class, 'entity');
|
||||
}
|
||||
|
||||
public function journalists(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Journalist::class, PartnerMedia::class);
|
||||
}
|
||||
|
||||
public function partnerMedia(): HasOne
|
||||
{
|
||||
return $this->hasOne(PartnerMedia::class);
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function verificationRequest(): HasOne
|
||||
{
|
||||
return $this->hasOne(VerificationRequest::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ protected function completed(Builder $query): void
|
||||
$query->where('status', CooperationStatus::COMPLETED);
|
||||
}
|
||||
|
||||
public function cooperationMedia(): HasMany
|
||||
public function cooperationMedias(): HasMany
|
||||
{
|
||||
return $this->hasMany(CooperationMedia::class);
|
||||
}
|
||||
@ -87,7 +87,7 @@ public function payments(): HasManyThrough
|
||||
);
|
||||
}
|
||||
|
||||
public function proposal(): HasMany
|
||||
public function proposals(): HasMany
|
||||
{
|
||||
return $this->hasMany(CooperationProposal::class);
|
||||
}
|
||||
|
||||
@ -3,9 +3,12 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\VerificationStatus;
|
||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@ -24,14 +27,10 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function partnerMedia(): BelongsTo
|
||||
#[Scope]
|
||||
public function pending(Builder $query): void
|
||||
{
|
||||
return $this->belongsTo(PartnerMedia::class);
|
||||
}
|
||||
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('status', VerificationStatus::PENDING);
|
||||
$query->where('status', VerificationStatus::PENDING);
|
||||
}
|
||||
|
||||
public static function dataChangeEntryLabels(): array
|
||||
@ -46,4 +45,14 @@ public static function dataChangeEntryLabels(): array
|
||||
'ukw_certificate_docs' => 'Dokumen Sertifikat UKW',
|
||||
];
|
||||
}
|
||||
|
||||
public function dataChangeRequests(): MorphMany
|
||||
{
|
||||
return $this->morphMany(DataChangeRequest::class, 'entity');
|
||||
}
|
||||
|
||||
public function partnerMedia(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PartnerMedia::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,10 +26,10 @@ class News extends Model implements HasMedia
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'views' => 'integer',
|
||||
'status' => NewsStatus::class,
|
||||
'published_at' => 'datetime',
|
||||
'author_id' => 'integer',
|
||||
'published_at' => 'datetime',
|
||||
'status' => NewsStatus::class,
|
||||
'views' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@ -58,6 +59,21 @@ protected function wherePivotPending(Builder $query): void
|
||||
$query->where('cooperation_media.status', ApprovalStatus::PENDING);
|
||||
}
|
||||
|
||||
public static function dataChangeEntryLabels(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Nama',
|
||||
'link' => 'Tautan',
|
||||
'address' => 'Alamat',
|
||||
'type' => 'Jenis',
|
||||
'classification' => 'Klasifikasi',
|
||||
'journalism_organization' => 'No. Organisasi Kewartawanan',
|
||||
'journalism_organization_docs' => 'Dokumen Organisasi Kewartawanan',
|
||||
'press_council_certificate' => 'No. Sertifikat Dewan Pers',
|
||||
'press_council_certificate_docs' => 'Dokumen Sertifikat Dewan Pers',
|
||||
];
|
||||
}
|
||||
|
||||
public function announcementMedias(): HasMany
|
||||
{
|
||||
return $this->hasMany(AnnouncementMedia::class);
|
||||
@ -91,6 +107,11 @@ public function cooperations(): BelongsToMany
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function dataChangeRequests(): MorphMany
|
||||
{
|
||||
return $this->morphMany(DataChangeRequest::class, 'entity');
|
||||
}
|
||||
|
||||
public function journalists(): HasMany
|
||||
{
|
||||
return $this->hasMany(Journalist::class);
|
||||
@ -108,19 +129,4 @@ public function taskAssignments(): BelongsToMany
|
||||
->withPivot(['status'])
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public static function dataChangeEntryLabels(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Nama',
|
||||
'link' => 'Tautan',
|
||||
'address' => 'Alamat',
|
||||
'type' => 'Jenis',
|
||||
'classification' => 'Klasifikasi',
|
||||
'journalism_organization' => 'No. Organisasi Kewartawanan',
|
||||
'journalism_organization_docs' => 'Dokumen Organisasi Kewartawanan',
|
||||
'press_council_certificate' => 'No. Sertifikat Dewan Pers',
|
||||
'press_council_certificate_docs' => 'Dokumen Sertifikat Dewan Pers',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,15 +36,6 @@ protected function casts(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
if ($this->company?->verificationRequest?->status === VerificationStatus::REJECTED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->is_active === IsActive::ACTIVE;
|
||||
}
|
||||
|
||||
#[Scope]
|
||||
protected function withoutDeveloper(Builder $query): void
|
||||
{
|
||||
@ -67,6 +58,15 @@ protected function superAdmin(Builder $query): void
|
||||
});
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
if ($this->company?->verificationRequest?->status === VerificationStatus::REJECTED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->is_active === IsActive::ACTIVE;
|
||||
}
|
||||
|
||||
public function company(): HasOne
|
||||
{
|
||||
return $this->hasOne(Company::class);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user