75 lines
2.1 KiB
PHP
75 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Media extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'media';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'address',
|
|
'link',
|
|
'type',
|
|
'classification',
|
|
'journalism_organization',
|
|
'journalism_organization_doc',
|
|
'press_council_certificate',
|
|
'press_council_certificate_doc',
|
|
'edit_description',
|
|
'edit_status',
|
|
'edit_rejection_reason',
|
|
'company_id'
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->hasOneThrough(
|
|
\App\Models\User::class, // model tujuan
|
|
\App\Models\Company::class, // model perantara
|
|
'id', // foreign key di Company (nyambung ke Media)
|
|
'id', // foreign key di User (nyambung ke Company)
|
|
'company_id', // foreign key di Media
|
|
'user_id' // foreign key di Company
|
|
);
|
|
}
|
|
|
|
|
|
public function company(){
|
|
return $this->belongsTo(Company::class, 'company_id', 'id')->withTrashed();
|
|
}
|
|
|
|
public function journalists(){
|
|
return $this->hasMany(Journalist::class, 'media_id', 'id')->withTrashed();
|
|
}
|
|
|
|
public function cooperations()
|
|
{
|
|
return $this->belongsToMany(Cooperation::class, 'media_cooperations', 'media_id', 'cooperation_id')
|
|
->using(MediaCooperation::class)
|
|
->withPivot(['status', 'rejection_reason'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
return $this->belongsToMany(Order::class, 'media_orders', 'media_id', 'order_id')
|
|
->using(MediaOrder::class)
|
|
->withPivot(['status', 'rejection_reason'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function reports(){
|
|
return $this->hasMany(Report::class, 'media_id', 'id');
|
|
}
|
|
|
|
public function completions(){
|
|
return $this->hasMany(CooperationCompletion::class, 'order_id', 'id');
|
|
}
|
|
}
|