Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Illuminate\Notifications\Notifiable;
- use Illuminate\Contracts\Auth\MustVerifyEmail;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use App\Mail\UserPassword;
- use Illuminate\Support\Facades\Mail;
- class User extends Authenticatable
- {
- use Notifiable;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name', 'email', 'password'
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password', 'remember_token',
- ];
- public function articles()
- {
- return $this->hasMany(Article::class);
- }
- public static function add($fields)
- {
- $user = new static;
- $user->fill($fields);
- $user->save();
- return $user;
- }
- public function edit($fields)
- {
- $this->fill($fields);
- $this->save();
- }
- public function editName($name)
- {
- $this->name = $name;
- $this->save();
- }
- public function generatePassword($email)
- {
- $password = rand(111111, 999999);
- if ($password != null) {
- $this->password = bcrypt($password);
- $this->save();
- }
- Mail::to($email)->send(new UserPassword($password));
- }
- public function getPhoto()
- {
- if ($this->image == null) {
- return '/images/users/avatar.jpg';
- }
- return '/storage/images/users/' . $this->image;
- }
- public function socialProviders()
- {
- return $this->hasMany(SocialProvider::class);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement