File manager - Edit - /home/autoph/public_html/projects/aha-api/app/Models/Customer.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Contracts\Auditable; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Auditable as AuditableTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; class Customer extends Model implements Auditable { use HasFactory, SoftDeletes, AuditableTrait; /** * The attributes that are NOT mass assignable. * */ protected $guarded = [ 'deleted_at', ]; /** * The attributes that should be cast. * * @var array<string, string> */ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; protected $appends = [ 'name', 'region_name', 'province_name', 'city_name', 'barangay_name' ]; /** * The vehicles that belong to the customer. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function vehicles() { $vehicles = $this->hasMany(Vehicle::class, 'owner_id'); if(!empty($this->aha_user_id)) $vehicles = $this->hasMany(Vehicle::class, 'aha_user_id', 'aha_user_id'); return $vehicles; } /** * The vehicles that belong to the customer. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function bookings() { return $this->hasMany(ServiceBooking::class, 'customer_id') ->where(function ($query) { $query->where('customer_id', $this->id) ->orWhere('aha_user_id', $this->aha_user_id); }); } /** * The OTPs that belong to the customer. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function otp() { return $this->hasMany(CustomerOTP::class, 'customer_id'); } public function getNameAttribute() { return ucwords(strtolower("{$this->firstname} {$this->lastname}")); } public function regionData() { return $this->hasOne(Region::class, 'region_code', 'region'); } public function provinceData() { return $this->hasOne(Province::class, 'province_code', 'province'); } public function cityData() { return $this->hasOne(City::class, 'city_code', 'city'); } public function barangayData() { return $this->hasOne(Barangay::class, 'geocode', 'barangay'); } public function getRegionNameAttribute() { return $this->regionData()->pluck('name')->first(); } public function getProvinceNameAttribute() { return $this->provinceData()->pluck('name')->first(); } public function getCityNameAttribute() { return $this->cityData()->pluck('name')->first(); } public function getBarangayNameAttribute() { return $this->barangayData()->pluck('name')->first(); } }
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.05 |
proxy
|
phpinfo
|
Settings