Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.44 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Notifications\Notifiable;
  6. use Illuminate\Contracts\Auth\MustVerifyEmail;
  7. use Illuminate\Foundation\Auth\User as Authenticatable;
  8. use App\Mail\UserPassword;
  9. use Illuminate\Support\Facades\Mail;
  10.  
  11. class User extends Authenticatable
  12. {
  13.     use Notifiable;
  14.  
  15.     /**
  16.      * The attributes that are mass assignable.
  17.      *
  18.      * @var array
  19.      */
  20.     protected $fillable = [
  21.         'name', 'email', 'password'
  22.     ];
  23.  
  24.     /**
  25.      * The attributes that should be hidden for arrays.
  26.      *
  27.      * @var array
  28.      */
  29.     protected $hidden = [
  30.         'password', 'remember_token',
  31.     ];
  32.  
  33.     public function articles()
  34.     {
  35.         return $this->hasMany(Article::class);
  36.     }
  37.  
  38.     public static function add($fields)
  39.     {
  40.         $user = new static;
  41.         $user->fill($fields);
  42.         $user->save();
  43.  
  44.         return $user;
  45.     }
  46.  
  47.     public function edit($fields)
  48.     {
  49.         $this->fill($fields);
  50.         $this->save();
  51.     }
  52.  
  53.     public function editName($name)
  54.     {
  55.         $this->name = $name;
  56.         $this->save();
  57.     }
  58.  
  59.     public function generatePassword($email)
  60.     {
  61.         $password = rand(111111, 999999);
  62.         if ($password != null) {
  63.             $this->password = bcrypt($password);
  64.             $this->save();
  65.         }
  66.         Mail::to($email)->send(new UserPassword($password));
  67.     }
  68.  
  69.     public function getPhoto()
  70.     {
  71.         if ($this->image == null) {
  72.             return '/images/users/avatar.jpg';
  73.         }
  74.         return '/storage/images/users/' . $this->image;
  75.     }
  76.  
  77.     public function socialProviders()
  78.     {
  79.         return $this->hasMany(SocialProvider::class);
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement