first
This commit is contained in:
48
modules/User/Models/UserInfo.php
Normal file
48
modules/User/Models/UserInfo.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Models;
|
||||
|
||||
use App\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class UserInfo extends Model
|
||||
{
|
||||
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
/**
|
||||
* Notes : 用户
|
||||
*
|
||||
* @Date : 2021/3/11 5:37 下午
|
||||
* @Author : < Jason.C >
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes : 获取头像的实际地址
|
||||
*
|
||||
* @Date : 2021/3/12 10:53 上午
|
||||
* @Author : < Jason.C >
|
||||
* @param $avatar
|
||||
* @return string
|
||||
*/
|
||||
public function getAvatarAttribute($avatar): string
|
||||
{
|
||||
if (empty($avatar)) {
|
||||
$avatar = config('user.avatar');
|
||||
}
|
||||
|
||||
if (Str::startsWith($avatar, 'http')) {
|
||||
return $avatar;
|
||||
}
|
||||
|
||||
return $avatar ? Storage::url($avatar) : '';
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user