File: /var/www/vhost/disk-apps/agile-selling-orl/app/User.php
<?php
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Schedula\Laravel\PassportSocialite\User\UserSocialAccount;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Notifications\Messages\MailMessage;
use App\User;
use App\Rol;
use App\Sucursal;
use App\UserInformation;
use App\Order;
use App\Mailbox;
use App\Message;
use App\Chat;
use App\Address;
use App\notifications;
class User extends Authenticatable implements UserSocialAccount
{
use HasApiTokens, Notifiable, SoftDeletes;
protected $dates = ['deleted_at'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'id', 'name', 'email', 'password', 'first_name', 'document', 'phone', 'active', 'email', 'password', 'rol_id', 'bo_price_list_id', 'bo_contact_person', 'bo_payment_term_type_id', 'bo_account_balance',
'bo_phone_1', 'bo_phone_2', 'bo_card_type', 'bo_valid', 'bo_tax_exempt'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function rol(){
return $this->belongsTo(Rol::class)->select(array('id','name'));
}
public function boPriceList(){
return $this->belongsTo(BoPriceList::class);
}
public function boSpecialPrices(){
return $this->hasMany(BoSpecialPrice::class);
}
public function boPaymentTermType(){
return $this->belongsTo(BoPaymentTermType::class);
}
public function boContactEmployeesUsers(){
return $this->hasMany(BoContactEmployeesUser::class);
}
public function userInfo(){
return $this->hasOne(UserInformation::class);
}
public function orders(){
return $this->hasMany(Order::class);
}
public function mailboxes(){
return $this->hasMany(Mailbox::class);
}
public function messages(){
return $this->hasMany(Message::class);
}
public function chats(){
return $this->hasOne(Chat::class);
}
public function notifications(){
return $this->hasMany(notifications::class);
}
public function addresses(){
return $this->hasMany(Address::class)->with(['coverage','boSalesTaxCode']);
}
public function topTenProducts(){
return $this->hasMany(TopTenProduct::class)->orderBy('quantity', 'desc');
}
/**
* Find user using social provider's id
*
* @param string $provider Provider name as requested from oauth e.g. facebook
* @param string $id User id of social provider
*
* @return User
*/
public static function findForPassportSocialite($provider,$id) {
$account = UserInformation::where('social_provider', $provider)->where('social_id', $id)->first();
$userAccount = User::find($account->user_id);
if($userAccount){
return $userAccount;
}
return;
}
/**
* Sends the password reset notification.
*
* @param string $token
*
* @return void
*/
public function sendPasswordResetNotification($token){
$this->notify(new CustomPassword($token));
}
}
class CustomPassword extends ResetPassword
{
public function toMail($notifiable)
{
return (new MailMessage)
->from(env('MAIL_USERNAME'))
->subject('Reestablacer contraseña ' . env('MAIL_FROM_NAME'))
->greeting('Hola,')
->line('Te estamos enviando este email porque hemos recibido una solicitud de reestablecer tu contraseña.')
->action('Reestablecer contraseña', url(config('app.url') . route('password.reset', $this->token, false)))
->line('Si no has solicitado reestablecer la contraseña, no es necesario realizar ninguna acción. Por favor contáctanos si tu no enviaste esta solicitud.');
}
}