tissue/app/User.php

75 lines
1.7 KiB
PHP
Raw Normal View History

2017-08-27 04:44:53 +09:00
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
2019-01-15 00:05:01 +09:00
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Auth;
2017-08-27 04:44:53 +09:00
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'is_protected', 'accept_analytics',
'display_name', 'description',
'twitter_id', 'twitter_name',
'private_likes',
2017-08-27 04:44:53 +09:00
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
2020-05-23 21:34:49 +09:00
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
// 'email_verified_at' => 'datetime',
];
/**
* このユーザのメールアドレスから、Gravatarの画像URLを生成します。
* @param int $size 画像サイズ
* @return string Gravatar 画像URL
*/
2019-01-15 00:05:01 +09:00
public function getProfileImageUrl($size = 30): string
{
$hash = md5(strtolower(trim($this->email)));
2019-01-15 00:05:01 +09:00
return '//www.gravatar.com/avatar/' . $hash . '?s=' . $size . '&d=retro';
}
/**
* このユーザがログイン中のユーザ本人であるかをチェックします。
* @return bool 本人かどうか
*/
public function isMe()
{
return Auth::check() && $this->id === Auth::user()->id;
}
2019-04-05 23:10:26 +09:00
2019-09-12 00:54:36 +09:00
public function ejaculations()
{
return $this->hasMany(Ejaculation::class);
}
2019-04-05 23:10:26 +09:00
public function likes()
{
return $this->hasMany(Like::class);
}
2017-08-27 04:44:53 +09:00
}