2018-07-20 15:07:16 +00:00
|
|
|
<?php
|
2018-07-24 14:33:49 +00:00
|
|
|
|
2018-07-20 15:07:16 +00:00
|
|
|
namespace Webkul\Customer\Models;
|
|
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
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;
|
2018-07-20 15:07:16 +00:00
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
|
|
|
|
|
class Customer extends Authenticatable
|
2018-07-20 15:07:16 +00:00
|
|
|
{
|
2018-07-24 14:33:49 +00:00
|
|
|
use Notifiable;
|
|
|
|
|
|
2018-07-20 15:07:16 +00:00
|
|
|
protected $table = 'customers';
|
2018-09-08 08:41:36 +00:00
|
|
|
|
2018-11-01 13:48:59 +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.
|
|
|
|
|
*/
|
2018-10-27 11:13:57 +00:00
|
|
|
public function addresses()
|
2018-10-26 13:43:01 +00:00
|
|
|
{
|
2018-10-27 11:13:57 +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()
|
2018-10-27 11:13:57 +00:00
|
|
|
{
|
|
|
|
|
return $this->hasOne(CustomerAddress::class, 'customer_id')->where('default_address', 1);
|
2018-10-26 13:43:01 +00:00
|
|
|
}
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|