*/ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', 'enabled' => 'boolean', ]; protected $appends = [ 'dealer_name', // 'created_by_name', ]; public function dealer() { return $this->belongsTo(Dealership::class); } public function getDealerNameAttribute() { return $this->dealer()->withTrashed()->pluck('name')->first(); } // public function getCreatedByNameAttribute() // { // if ($this->created_by) { // if($user = Employee::where('employee_id', $this->created_by)->first()) { // return ucwords(strtolower("{$user->u_fname} {$user->u_lname}")); // } // return null; // } // return null; // } public function user() { return $this->belongsTo(User::class, 'created_by'); } public function scopeEnabled($query) { return $query->where('enabled', true); } }