ユーザの本人判定をModelに逃した

This commit is contained in:
shibafu
2017-11-05 22:29:09 +09:00
parent 7e9501ab9d
commit 95204736ef
5 changed files with 19 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Auth;
class User extends Authenticatable
{
@@ -35,8 +36,18 @@ class User extends Authenticatable
* @param int $size 画像サイズ
* @return string Gravatar 画像URL
*/
public function getProfileImageUrl($size = 30) : string {
public function getProfileImageUrl($size = 30) : string
{
$hash = md5(strtolower(trim($this->email)));
return '//www.gravatar.com/avatar/' . $hash . '?s=' . $size;
}
/**
* このユーザがログイン中のユーザ本人であるかをチェックします。
* @return bool 本人かどうか
*/
public function isMe()
{
return Auth::check() && $this->id === Auth::user()->id;
}
}