Consultancy.php
1 <?php 2 3 namespace App\Models; 4 5 use Illuminate\Database\Eloquent\Factories\HasFactory; 6 use Illuminate\Database\Eloquent\Model; 7 use Illuminate\Database\Eloquent\SoftDeletes; 8 use Spatie\Activitylog\LogOptions; 9 use Spatie\Activitylog\Traits\LogsActivity; 10 11 class Consultancy extends Model 12 { 13 use HasFactory, LogsActivity, SoftDeletes; 14 15 protected $guarded = []; 16 17 public static function create(array $data = []) 18 { 19 $consultancy = static::query()->create([ 20 'name' => $data['name'], 21 ]); 22 23 PointOfContact::create([ 24 'address' => array_key_exists('address', $data) ? $data['address'] : null, 25 'phone' => array_key_exists('phone', $data) ? $data['phone'] : null, 26 'email' => array_key_exists('email', $data) ? $data['email'] : null, 27 'gpg' => array_key_exists('gpg', $data) ? $data['gpg'] : null, 28 'principal' => true, 29 'point_of_contact_type_id' => PointOfContactType::CONSULTANCY, 30 'consultancy_id' => $consultancy->id, 31 ]); 32 33 return $consultancy; 34 } 35 36 public function consultants() 37 { 38 return $this->hasMany(Consultant::class); 39 } 40 41 public function pointsOfContact() 42 { 43 return $this->hasMany(PointOfContact::class); 44 } 45 46 public function getActivitylogOptions(): LogOptions 47 { 48 return LogOptions::defaults() 49 ->logOnly([ 50 'name', 51 ])->logOnlyDirty() 52 ->dontSubmitEmptyLogs(); 53 } 54 }