sarga/packages/Webkul/Customer/src/Models/Customer.php

66 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace Webkul\Customer\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
2018-10-23 11:51:04 +00:00
use Webkul\Customer\Models\CustomerGroup;
2018-10-15 08:22:27 +00:00
use Webkul\Sales\Models\Order;
2018-10-25 07:46:45 +00:00
use Webkul\Customer\Notifications\CustomerResetPassword;
class Customer extends Authenticatable
{
use Notifiable;
protected $table = 'customers';
2018-09-08 08:41:36 +00:00
protected $fillable = ['first_name', 'channel_id', 'last_name', 'gender', 'date_of_birth', 'email', 'password', 'customer_group_id', 'subscribed_to_news_letter'];
2018-09-08 08:41:36 +00:00
2018-10-23 11:45:44 +00:00
protected $hidden = ['password', 'remember_token'];
2018-08-30 13:22:15 +00:00
2018-09-08 08:41:36 +00:00
protected $with = ['customerGroup'];
/**
* Get the customer full name.
*/
2018-08-30 13:22:15 +00:00
public function getNameAttribute() {
return ucfirst($this->first_name) . ' ' . ucfirst($this->last_name);
}
2018-09-08 08:41:36 +00:00
/**
* Get the customer group that owns the customer.
*/
public function customerGroup()
{
2018-10-23 11:51:04 +00:00
return $this->belongsTo(CustomerGroup::class);
2018-09-08 08:41:36 +00:00
}
2018-10-25 07:46:45 +00:00
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new CustomerResetPassword($token));
}
2018-10-26 13:43:01 +00:00
/**
* Get the customer address that owns the customer.
*/
public function addresses()
2018-10-26 13:43:01 +00:00
{
return $this->hasMany(CustomerAddress::class, 'customer_id');
}
/**
* Get default customer address that owns the customer.
*/
2018-10-30 12:46:40 +00:00
public function default_address()
{
return $this->hasOne(CustomerAddress::class, 'customer_id')->where('default_address', 1);
2018-10-26 13:43:01 +00:00
}
}